xref: /netbsd-src/sys/arch/evbarm/tsarm/isa/isa_machdep.c (revision cd22f25e6f6d1cc1f197fe8c5468a80f51d1c4e1)
1 /*	$NetBSD: isa_machdep.c,v 1.4 2008/04/28 20:23:17 martin 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.4 2008/04/28 20:23:17 martin 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/malloc.h>
81 #include <sys/proc.h>
82 
83 #include <machine/bus.h>
84 
85 #include <machine/intr.h>
86 #include <machine/pio.h>
87 #include <machine/bootconfig.h>
88 #include <machine/isa_machdep.h>
89 
90 #include <dev/isa/isareg.h>
91 #include <dev/isa/isavar.h>
92 
93 #include <arm/ep93xx/ep93xxvar.h>
94 #include <uvm/uvm_extern.h>
95 
96 /* prototypes */
97 void isa_tsarm_init(u_int, u_int);
98 struct arm32_isa_chipset isa_chipset_tag;
99 
100 static unsigned int ep93xxirq[3] = { 20, 33, 40 };
101 /* only have 3 irqs connected to real lines on TS-7xxx */
102 static unsigned int isairq[3] = { 5, 6, 7 };
103 static unsigned int isairq_nhandlers[3] = { 0, 0, 0 };
104 
105 int
106 isa_intr_alloc(ic, mask, type, irq)
107 	isa_chipset_tag_t ic;
108 	int mask;
109 	int type;
110 	int *irq;
111 {
112 	int i, bestirq, count;
113 
114 	if (type == IST_NONE)
115 		panic("intr_alloc: bogus type");
116 
117 	bestirq = -1;
118 	count = -1;
119 
120 	/* some interrupts should never be dynamically allocated */
121 	mask &= 0x00e0;
122 
123 	for (i = 0; i < sizeof(isairq); i++) {
124 		if ((mask & (1<<isairq[i])) == 0)
125 			continue;
126 		if (isairq_nhandlers[i] < count || count == -1) {
127 			bestirq = isairq[i];
128 			count = isairq_nhandlers[i];
129 		}
130 	}
131 
132 	if (bestirq == -1)
133 		return (1);
134 
135 	*irq = bestirq;
136 
137 	return (0);
138 }
139 
140 const struct evcnt *
141 isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
142 {
143 	return NULL;
144 }
145 
146 /*
147  * Set up an interrupt handler to start being called.
148  */
149 void *
150 isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
151 	isa_chipset_tag_t ic;
152 	int irq;
153 	int type;
154 	int level;
155 	int (*ih_fun) __P((void *));
156 	void *ih_arg;
157 {
158 	int epirq = -1, i;
159 	/* Find real EP93XX irq number */
160 	for(i = 0; i < sizeof(isairq); i++) {
161 		if (irq == isairq[i]) epirq = ep93xxirq[i];
162 	}
163 
164 	if (epirq == -1)
165 		return NULL;
166 	else
167 		return (ep93xx_intr_establish(epirq, level, ih_fun, ih_arg));
168 }
169 
170 /*
171  * Deregister an interrupt handler.
172  */
173 void
174 isa_intr_disestablish(ic, arg)
175 	isa_chipset_tag_t ic;
176 	void *arg;
177 {
178 	ep93xx_intr_disestablish(arg);
179 }
180 
181 void
182 isa_tsarm_init(iobase16, membase16)
183         u_int iobase16, membase16;
184 {
185         isa_io_init(iobase16, membase16);
186 }
187 
188 
189 /*
190  * isa_intr_init()
191  *
192  * TODO: Set up ISA IRQ 5 on GPIO pin
193  */
194 void
195 isa_intr_init(void)
196 {
197 }
198 
199 void
200 isa_attach_hook(parent, self, iba)
201 	struct device *parent, *self;
202 	struct isabus_attach_args *iba;
203 {
204 	/*
205 	 * Since we can only have one ISA bus, we just use a single
206 	 * statically allocated ISA chipset structure.  Pass it up
207 	 * now.
208 	 */
209 	iba->iba_ic = &isa_chipset_tag;
210 	printf(": PC/104 expansion bus");
211 }
212