OsdInterrupt.c revision 1.1.2.2 1 1.1.2.2 tron /* $NetBSD: OsdInterrupt.c,v 1.1.2.2 2006/03/28 09:42:03 tron Exp $ */
2 1.1.2.2 tron
3 1.1.2.2 tron /*
4 1.1.2.2 tron * Copyright 2001 Wasabi Systems, Inc.
5 1.1.2.2 tron * All rights reserved.
6 1.1.2.2 tron *
7 1.1.2.2 tron * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1.2.2 tron *
9 1.1.2.2 tron * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 tron * modification, are permitted provided that the following conditions
11 1.1.2.2 tron * are met:
12 1.1.2.2 tron * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 tron * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 tron * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 tron * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 tron * documentation and/or other materials provided with the distribution.
17 1.1.2.2 tron * 3. All advertising materials mentioning features or use of this software
18 1.1.2.2 tron * must display the following acknowledgement:
19 1.1.2.2 tron * This product includes software developed for the NetBSD Project by
20 1.1.2.2 tron * Wasabi Systems, Inc.
21 1.1.2.2 tron * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.2 tron * or promote products derived from this software without specific prior
23 1.1.2.2 tron * written permission.
24 1.1.2.2 tron *
25 1.1.2.2 tron * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.2 tron * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.2 tron * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.2 tron * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.2 tron * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.2 tron * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.2 tron * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.2 tron * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.2 tron * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.2 tron * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.2 tron * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.2 tron */
37 1.1.2.2 tron
38 1.1.2.2 tron /*
39 1.1.2.2 tron * OS Services Layer
40 1.1.2.2 tron *
41 1.1.2.2 tron * 6.5: Interrupt Handling
42 1.1.2.2 tron */
43 1.1.2.2 tron
44 1.1.2.2 tron #include <sys/cdefs.h>
45 1.1.2.2 tron __KERNEL_RCSID(0, "$NetBSD: OsdInterrupt.c,v 1.1.2.2 2006/03/28 09:42:03 tron Exp $");
46 1.1.2.2 tron
47 1.1.2.2 tron #include <sys/param.h>
48 1.1.2.2 tron #include <sys/malloc.h>
49 1.1.2.2 tron #include <sys/lock.h>
50 1.1.2.2 tron #include <sys/queue.h>
51 1.1.2.2 tron
52 1.1.2.2 tron #include <dev/acpi/acpica.h>
53 1.1.2.2 tron
54 1.1.2.2 tron #include <machine/acpi_machdep.h>
55 1.1.2.2 tron
56 1.1.2.2 tron #define _COMPONENT ACPI_OS_SERVICES
57 1.1.2.2 tron ACPI_MODULE_NAME("INTERRUPT")
58 1.1.2.2 tron
59 1.1.2.2 tron MALLOC_DEFINE(M_ACPI, "acpi", "Advanced Configuration and Power Interface");
60 1.1.2.2 tron
61 1.1.2.2 tron /*
62 1.1.2.2 tron * We're lucky -- ACPI uses the same convention for interrupt service
63 1.1.2.2 tron * routine return values at NetBSD does -- so we can just ask MD code
64 1.1.2.2 tron * to hook it up directly (ACPI interrupts are always level triggered
65 1.1.2.2 tron * and shareable, and return 0 for "not handled" and 1 for "handled").
66 1.1.2.2 tron */
67 1.1.2.2 tron
68 1.1.2.2 tron struct acpi_interrupt_handler {
69 1.1.2.2 tron LIST_ENTRY(acpi_interrupt_handler) aih_list;
70 1.1.2.2 tron UINT32 aih_intrnum;
71 1.1.2.2 tron ACPI_OSD_HANDLER aih_func;
72 1.1.2.2 tron void *aih_ih;
73 1.1.2.2 tron };
74 1.1.2.2 tron
75 1.1.2.2 tron static LIST_HEAD(, acpi_interrupt_handler) acpi_interrupt_list =
76 1.1.2.2 tron LIST_HEAD_INITIALIZER(&acpi_interrupt_list);
77 1.1.2.2 tron static struct simplelock acpi_interrupt_list_slock = SIMPLELOCK_INITIALIZER;
78 1.1.2.2 tron
79 1.1.2.2 tron #define ACPI_INTERRUPT_LIST_LOCK(s) \
80 1.1.2.2 tron do { \
81 1.1.2.2 tron (s) = splhigh(); \
82 1.1.2.2 tron simple_lock(&acpi_interrupt_list_slock); \
83 1.1.2.2 tron } while (/*CONSTCOND*/0)
84 1.1.2.2 tron
85 1.1.2.2 tron #define ACPI_INTERRUPT_LIST_UNLOCK(s) \
86 1.1.2.2 tron do { \
87 1.1.2.2 tron simple_unlock(&acpi_interrupt_list_slock); \
88 1.1.2.2 tron splx((s)); \
89 1.1.2.2 tron } while (/*CONSTCOND*/0)
90 1.1.2.2 tron
91 1.1.2.2 tron /*
92 1.1.2.2 tron * AcpiOsInstallInterruptHandler:
93 1.1.2.2 tron *
94 1.1.2.2 tron * Install a handler for a hardware interrupt level.
95 1.1.2.2 tron */
96 1.1.2.2 tron ACPI_STATUS
97 1.1.2.2 tron AcpiOsInstallInterruptHandler(UINT32 InterruptNumber,
98 1.1.2.2 tron ACPI_OSD_HANDLER ServiceRoutine, void *Context)
99 1.1.2.2 tron {
100 1.1.2.2 tron struct acpi_interrupt_handler *aih;
101 1.1.2.2 tron ACPI_STATUS rv;
102 1.1.2.2 tron int s;
103 1.1.2.2 tron
104 1.1.2.2 tron ACPI_FUNCTION_TRACE(__FUNCTION__);
105 1.1.2.2 tron
106 1.1.2.2 tron if (InterruptNumber < 0 || InterruptNumber > 255)
107 1.1.2.2 tron return_ACPI_STATUS(AE_BAD_PARAMETER);
108 1.1.2.2 tron if (ServiceRoutine == NULL)
109 1.1.2.2 tron return_ACPI_STATUS(AE_BAD_PARAMETER);
110 1.1.2.2 tron
111 1.1.2.2 tron aih = malloc(sizeof(*aih), M_ACPI, M_NOWAIT);
112 1.1.2.2 tron if (aih == NULL)
113 1.1.2.2 tron return_ACPI_STATUS(AE_NO_MEMORY);
114 1.1.2.2 tron
115 1.1.2.2 tron aih->aih_intrnum = InterruptNumber;
116 1.1.2.2 tron aih->aih_func = ServiceRoutine;
117 1.1.2.2 tron
118 1.1.2.2 tron rv = acpi_md_OsInstallInterruptHandler(InterruptNumber,
119 1.1.2.2 tron ServiceRoutine, Context, &aih->aih_ih);
120 1.1.2.2 tron if (rv == AE_OK) {
121 1.1.2.2 tron ACPI_INTERRUPT_LIST_LOCK(s);
122 1.1.2.2 tron LIST_INSERT_HEAD(&acpi_interrupt_list, aih, aih_list);
123 1.1.2.2 tron ACPI_INTERRUPT_LIST_UNLOCK(s);
124 1.1.2.2 tron } else
125 1.1.2.2 tron free(aih, M_ACPI);
126 1.1.2.2 tron
127 1.1.2.2 tron return_ACPI_STATUS(rv);
128 1.1.2.2 tron }
129 1.1.2.2 tron
130 1.1.2.2 tron /*
131 1.1.2.2 tron * AcpiOsRemoveInterruptHandler:
132 1.1.2.2 tron *
133 1.1.2.2 tron * Remove an interrupt handler.
134 1.1.2.2 tron */
135 1.1.2.2 tron ACPI_STATUS
136 1.1.2.2 tron AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber,
137 1.1.2.2 tron ACPI_OSD_HANDLER ServiceRoutine)
138 1.1.2.2 tron {
139 1.1.2.2 tron struct acpi_interrupt_handler *aih;
140 1.1.2.2 tron int s;
141 1.1.2.2 tron
142 1.1.2.2 tron ACPI_FUNCTION_TRACE(__FUNCTION__);
143 1.1.2.2 tron
144 1.1.2.2 tron if (InterruptNumber < 0 || InterruptNumber > 255)
145 1.1.2.2 tron return_ACPI_STATUS(AE_BAD_PARAMETER);
146 1.1.2.2 tron if (ServiceRoutine == NULL)
147 1.1.2.2 tron return_ACPI_STATUS(AE_BAD_PARAMETER);
148 1.1.2.2 tron
149 1.1.2.2 tron ACPI_INTERRUPT_LIST_LOCK(s);
150 1.1.2.2 tron LIST_FOREACH(aih, &acpi_interrupt_list, aih_list) {
151 1.1.2.2 tron if (aih->aih_intrnum == InterruptNumber &&
152 1.1.2.2 tron aih->aih_func == ServiceRoutine) {
153 1.1.2.2 tron LIST_REMOVE(aih, aih_list);
154 1.1.2.2 tron ACPI_INTERRUPT_LIST_UNLOCK(s);
155 1.1.2.2 tron acpi_md_OsRemoveInterruptHandler(aih->aih_ih);
156 1.1.2.2 tron free(aih, M_ACPI);
157 1.1.2.2 tron return_ACPI_STATUS(AE_OK);
158 1.1.2.2 tron }
159 1.1.2.2 tron }
160 1.1.2.2 tron ACPI_INTERRUPT_LIST_UNLOCK(s);
161 1.1.2.2 tron return_ACPI_STATUS(AE_NOT_EXIST);
162 1.1.2.2 tron }
163