1 /* $NetBSD: isa_machdep.c,v 1.14 2023/12/20 13:55:18 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1996-1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jesse Off
9 *
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Mark Brinicombe, Charles M. Hannum and by Jason R. Thorpe of the
12 * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 /*-
37 * Copyright (c) 1991 The Regents of the University of California.
38 * All rights reserved.
39 *
40 * This code is derived from software contributed to Berkeley by
41 * William Jolitz.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)isa.c 7.2 (Berkeley) 5/13/91
68 */
69
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.14 2023/12/20 13:55:18 thorpej Exp $");
72
73 #include "opt_irqstats.h"
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/kernel.h>
78 #include <sys/syslog.h>
79 #include <sys/device.h>
80 #include <sys/proc.h>
81
82 #include <sys/bus.h>
83
84 #include <machine/intr.h>
85 #include <machine/pio.h>
86 #include <machine/bootconfig.h>
87 #include <machine/isa_machdep.h>
88
89 #include <dev/isa/isareg.h>
90 #include <dev/isa/isavar.h>
91
92 #include <arm/ep93xx/ep93xxvar.h>
93 #include <uvm/uvm_extern.h>
94
95 /* prototypes */
96 void isa_tsarm_init(u_int, u_int);
97 struct arm32_isa_chipset isa_chipset_tag;
98
99 static unsigned int ep93xxirq[3] = { 20, 33, 40 };
100 /* only have 3 irqs connected to real lines on TS-7xxx */
101 static unsigned int isairq[3] = { 5, 6, 7 };
102 static unsigned int isairq_nhandlers[3] = { 0, 0, 0 };
103
104 int
isa_intr_alloc(isa_chipset_tag_t ic,int mask,int type,int * irq)105 isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq)
106 {
107 int i, bestirq, count;
108
109 if (type == IST_NONE)
110 panic("intr_alloc: bogus type");
111
112 bestirq = -1;
113 count = -1;
114
115 /* some interrupts should never be dynamically allocated */
116 mask &= 0x00e0;
117
118 for (i = 0; i < __arraycount(isairq); i++) {
119 if ((mask & (1<<isairq[i])) == 0)
120 continue;
121 if (isairq_nhandlers[i] < count || count == -1) {
122 bestirq = isairq[i];
123 count = isairq_nhandlers[i];
124 }
125 }
126
127 if (bestirq == -1)
128 return (1);
129
130 *irq = bestirq;
131
132 return (0);
133 }
134
135 const struct evcnt *
isa_intr_evcnt(isa_chipset_tag_t ic,int irq)136 isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
137 {
138 return NULL;
139 }
140
141 /*
142 * Set up an interrupt handler to start being called.
143 */
144 void *
isa_intr_establish(isa_chipset_tag_t ic,int irq,int type,int level,int (* ih_fun)(void *),void * ih_arg)145 isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level, int (*ih_fun)(void *), void *ih_arg)
146 {
147 int epirq = -1, i;
148 /* Find real EP93XX irq number */
149 for(i = 0; i < __arraycount(isairq); i++) {
150 if (irq == isairq[i]) epirq = ep93xxirq[i];
151 }
152
153 if (epirq == -1)
154 return NULL;
155 else
156 return (ep93xx_intr_establish(epirq, level, ih_fun, ih_arg));
157 }
158
159 /*
160 * Deregister an interrupt handler.
161 */
162 void
isa_intr_disestablish(isa_chipset_tag_t ic,void * arg)163 isa_intr_disestablish(isa_chipset_tag_t ic, void *arg)
164 {
165 ep93xx_intr_disestablish(arg);
166 }
167
168 void
isa_tsarm_init(u_int iobase16,u_int membase16)169 isa_tsarm_init(u_int iobase16, u_int membase16)
170 {
171 isa_io_init(iobase16, membase16);
172 }
173
174
175 /*
176 * isa_intr_init()
177 *
178 * TODO: Set up ISA IRQ 5 on GPIO pin
179 */
180 void
isa_intr_init(void)181 isa_intr_init(void)
182 {
183 }
184
185 void
isa_attach_hook(device_t parent,device_t self,struct isabus_attach_args * iba)186 isa_attach_hook(device_t parent, device_t self, struct isabus_attach_args *iba)
187 {
188 /*
189 * Since we can only have one ISA bus, we just use a single
190 * statically allocated ISA chipset structure. Pass it up
191 * now.
192 */
193 iba->iba_ic = &isa_chipset_tag;
194 printf(": PC/104 expansion bus");
195 }
196
197 void
isa_detach_hook(isa_chipset_tag_t ic,device_t self)198 isa_detach_hook(isa_chipset_tag_t ic, device_t self)
199 {
200 }
201