2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/acpica/Osd/OsdInterrupt.c,v 1.17 2004/04/14 03:41:06 njl Exp $
28 * $DragonFly: src/sys/dev/acpica5/Osd/OsdInterrupt.c,v 1.7 2006/10/25 20:55:52 dillon Exp $
32 * 6.5 : Interrupt handling
35 #include <sys/param.h>
36 #include <sys/kernel.h>
39 #include <sys/thread2.h>
40 #include <sys/machintr.h>
44 #include <dev/acpica5/acpivar.h>
45 #include <dev/acpica5/acpi_sci_var.h>
47 #define _COMPONENT ACPI_OS_SERVICES
48 ACPI_MODULE_NAME("INTERRUPT")
50 static void InterruptWrapper(void *arg);
52 static ACPI_OSD_HANDLER InterruptHandler;
55 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber,
56 ACPI_OSD_HANDLER ServiceRoutine, void *Context)
58 struct acpi_softc *sc;
61 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
63 if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL)
64 panic("can't find ACPI device to register interrupt");
65 if (sc->acpi_dev == NULL)
66 panic("acpi softc has invalid device");
75 * - SCI is disabled by user
76 * - No suitable interrupt mode for SCI
78 if (!acpi_sci_enabled())
79 return_ACPI_STATUS (AE_OK);
81 if (InterruptNumber < 0 || InterruptNumber > 255)
82 return_ACPI_STATUS (AE_BAD_PARAMETER);
83 if (ServiceRoutine == NULL)
84 return_ACPI_STATUS (AE_BAD_PARAMETER);
85 if (InterruptHandler != NULL) {
86 device_printf(sc->acpi_dev, "interrupt handler already installed\n");
87 return_ACPI_STATUS (AE_ALREADY_EXISTS);
89 InterruptHandler = ServiceRoutine;
92 if (acpi_sci_pci_shariable())
93 flags |= RF_SHAREABLE;
95 /* Set up the interrupt resource. */
97 bus_set_resource(sc->acpi_dev, SYS_RES_IRQ, 0, InterruptNumber, 1,
98 machintr_intr_cpuid(InterruptNumber));
99 sc->acpi_irq = bus_alloc_resource_any(sc->acpi_dev, SYS_RES_IRQ,
100 &sc->acpi_irq_rid, flags);
101 if (sc->acpi_irq == NULL) {
102 device_printf(sc->acpi_dev, "could not allocate interrupt\n");
105 if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, 0,
106 InterruptWrapper, Context, &sc->acpi_irq_handle, NULL)) {
107 device_printf(sc->acpi_dev, "could not set up interrupt\n");
111 return_ACPI_STATUS (AE_OK);
114 if (sc->acpi_irq_handle)
115 bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle);
116 sc->acpi_irq_handle = NULL;
118 bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq);
120 bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0);
121 InterruptHandler = NULL;
123 return_ACPI_STATUS (AE_ALREADY_EXISTS);
127 AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine)
129 struct acpi_softc *sc;
131 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
133 if (!acpi_sci_enabled())
134 return_ACPI_STATUS (AE_OK);
136 if (InterruptNumber < 0 || InterruptNumber > 255)
137 return_ACPI_STATUS (AE_BAD_PARAMETER);
138 if (ServiceRoutine == NULL)
139 return_ACPI_STATUS (AE_BAD_PARAMETER);
141 if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL)
142 panic("can't find ACPI device to deregister interrupt");
144 if (sc->acpi_irq == NULL)
145 return_ACPI_STATUS (AE_NOT_EXIST);
147 bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle);
148 bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq);
149 bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0);
152 InterruptHandler = NULL;
154 return_ACPI_STATUS (AE_OK);
158 InterruptWrapper(void *arg)
161 InterruptHandler(arg);