1 /*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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. 14 * 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 25 * SUCH DAMAGE. 26 */ 27 28 /* 29 * 6.5 : Interrupt handling 30 */ 31 32 #include <sys/cdefs.h> 33 __FBSDID("$FreeBSD$"); 34 35 #include <sys/param.h> 36 #include <sys/kernel.h> 37 #include <sys/bus.h> 38 #include <machine/bus.h> 39 #include <machine/resource.h> 40 #include <sys/rman.h> 41 42 #include <contrib/dev/acpica/include/acpi.h> 43 #include <contrib/dev/acpica/include/accommon.h> 44 45 #include <dev/acpica/acpivar.h> 46 47 #define _COMPONENT ACPI_OS_SERVICES 48 ACPI_MODULE_NAME("INTERRUPT") 49 50 static UINT32 InterruptOverride = 0; 51 52 ACPI_STATUS 53 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, 54 ACPI_OSD_HANDLER ServiceRoutine, void *Context) 55 { 56 struct acpi_softc *sc; 57 58 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 59 60 if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL) 61 panic("can't find ACPI device to register interrupt"); 62 if (sc->acpi_dev == NULL) 63 panic("acpi softc has invalid device"); 64 65 if (InterruptNumber < 0 || InterruptNumber > 255) 66 return_ACPI_STATUS (AE_BAD_PARAMETER); 67 if (ServiceRoutine == NULL) 68 return_ACPI_STATUS (AE_BAD_PARAMETER); 69 70 /* 71 * If the MADT contained an interrupt override directive for the SCI, 72 * we use that value instead of the one from the FADT. 73 */ 74 if (InterruptOverride != 0) { 75 device_printf(sc->acpi_dev, 76 "Overriding SCI Interrupt from IRQ %u to IRQ %u\n", 77 InterruptNumber, InterruptOverride); 78 InterruptNumber = InterruptOverride; 79 } 80 81 /* Set up the interrupt resource. */ 82 sc->acpi_irq_rid = 0; 83 bus_set_resource(sc->acpi_dev, SYS_RES_IRQ, 0, InterruptNumber, 1); 84 sc->acpi_irq = bus_alloc_resource_any(sc->acpi_dev, SYS_RES_IRQ, 85 &sc->acpi_irq_rid, RF_SHAREABLE | RF_ACTIVE); 86 if (sc->acpi_irq == NULL) { 87 device_printf(sc->acpi_dev, "could not allocate interrupt\n"); 88 goto error; 89 } 90 if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, INTR_TYPE_MISC|INTR_MPSAFE, 91 NULL, (driver_intr_t *)ServiceRoutine, Context, &sc->acpi_irq_handle)) { 92 device_printf(sc->acpi_dev, "could not set up interrupt\n"); 93 goto error; 94 } 95 96 return_ACPI_STATUS (AE_OK); 97 98 error: 99 if (sc->acpi_irq_handle) 100 bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle); 101 sc->acpi_irq_handle = NULL; 102 if (sc->acpi_irq) 103 bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq); 104 sc->acpi_irq = NULL; 105 bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0); 106 107 return_ACPI_STATUS (AE_ALREADY_EXISTS); 108 } 109 110 ACPI_STATUS 111 AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine) 112 { 113 struct acpi_softc *sc; 114 115 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 116 117 if (InterruptNumber < 0 || InterruptNumber > 255) 118 return_ACPI_STATUS (AE_BAD_PARAMETER); 119 if (ServiceRoutine == NULL) 120 return_ACPI_STATUS (AE_BAD_PARAMETER); 121 122 if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL) 123 panic("can't find ACPI device to deregister interrupt"); 124 125 if (sc->acpi_irq == NULL) 126 return_ACPI_STATUS (AE_NOT_EXIST); 127 128 bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle); 129 bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq); 130 bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0); 131 132 sc->acpi_irq = NULL; 133 134 return_ACPI_STATUS (AE_OK); 135 } 136 137 ACPI_STATUS 138 acpi_OverrideInterruptLevel(UINT32 InterruptNumber) 139 { 140 141 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 142 143 if (InterruptOverride != 0) 144 return_ACPI_STATUS (AE_ALREADY_EXISTS); 145 InterruptOverride = InterruptNumber; 146 return_ACPI_STATUS (AE_OK); 147 } 148