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