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.15 2003/11/12 16:24:16 jhb Exp $
28 * $DragonFly: src/sys/dev/acpica5/Osd/OsdInterrupt.c,v 1.1 2004/02/21 06:48:09 dillon Exp $
32 * 6.5 : Interrupt handling
38 #include <machine/resource.h>
39 #include <machine/bus.h>
42 #include <dev/acpica5/acpivar.h>
44 #define _COMPONENT ACPI_OS_SERVICES
45 ACPI_MODULE_NAME("INTERRUPT")
47 static void InterruptWrapper(void *arg);
48 static OSD_HANDLER InterruptHandler;
50 static UINT32 InterruptOverride = 0;
53 * XXX this does not correctly free resources in the case of partically successful
57 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, OSD_HANDLER ServiceRoutine, void *Context)
59 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");
68 if ((InterruptNumber < 0) || (InterruptNumber > 255))
69 return_ACPI_STATUS(AE_BAD_PARAMETER);
70 if (ServiceRoutine == NULL)
71 return_ACPI_STATUS(AE_BAD_PARAMETER);
72 if (InterruptHandler != NULL && InterruptHandler != ServiceRoutine) {
73 device_printf(sc->acpi_dev, "can't register more than one ACPI interrupt\n");
74 return_ACPI_STATUS(AE_BAD_PARAMETER);
76 InterruptHandler = ServiceRoutine;
79 * This isn't strictly true, as we ought to be able to handle > 1 interrupt. The ACPI
80 * spec doesn't call for this though.
82 if (sc->acpi_irq != NULL) {
83 device_printf(sc->acpi_dev, "attempt to register more than one interrupt handler\n");
84 return_ACPI_STATUS(AE_ALREADY_EXISTS);
87 if (InterruptOverride != 0) {
88 device_printf(sc->acpi_dev,
89 "Overriding SCI Interrupt from IRQ %u to IRQ %u\n",
90 InterruptNumber, InterruptOverride);
91 InterruptNumber = InterruptOverride;
93 bus_set_resource(sc->acpi_dev, SYS_RES_IRQ, 0, InterruptNumber, 1);
94 if ((sc->acpi_irq = bus_alloc_resource(sc->acpi_dev, SYS_RES_IRQ, &sc->acpi_irq_rid, 0, ~0, 1,
95 RF_SHAREABLE | RF_ACTIVE)) == NULL) {
96 device_printf(sc->acpi_dev, "could not allocate SCI interrupt\n");
97 return_ACPI_STATUS(AE_ALREADY_EXISTS);
99 if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, INTR_TYPE_MISC, (driver_intr_t *)InterruptWrapper,
100 Context, &sc->acpi_irq_handle)) {
101 device_printf(sc->acpi_dev, "could not set up SCI interrupt\n");
102 return_ACPI_STATUS(AE_ALREADY_EXISTS);
105 return_ACPI_STATUS(AE_OK);
109 AcpiOsRemoveInterruptHandler (UINT32 InterruptNumber, OSD_HANDLER ServiceRoutine)
111 struct acpi_softc *sc;
113 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
115 if ((InterruptNumber < 0) || (InterruptNumber > 255))
116 return_ACPI_STATUS(AE_BAD_PARAMETER);
117 if (ServiceRoutine == NULL)
118 return_ACPI_STATUS(AE_BAD_PARAMETER);
120 if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL)
121 panic("can't find ACPI device to deregister interrupt");
123 if (sc->acpi_irq == NULL)
124 return_ACPI_STATUS(AE_NOT_EXIST);
126 bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle);
127 bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq);
128 bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0);
132 return_ACPI_STATUS(AE_OK);
136 acpi_OverrideInterruptLevel(UINT32 InterruptNumber)
139 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
141 if (InterruptOverride != 0)
142 return_ACPI_STATUS(AE_ALREADY_EXISTS);
143 InterruptOverride = InterruptNumber;
144 return_ACPI_STATUS(AE_OK);
148 * Interrupt handler wrapper.
151 InterruptWrapper(void *arg)
156 InterruptHandler(arg);