xref: /netbsd/sys/arch/hp300/hp300/bus_space.c (revision c4a72b64)
1 /*	$NetBSD: bus_space.c,v 1.6 2002/09/27 15:36:02 provos Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Implementation of bus_space mapping for the hp300.
41  */
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.6 2002/09/27 15:36:02 provos Exp $");
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/extent.h>
49 
50 #include <machine/autoconf.h>
51 #include <machine/bus.h>
52 
53 #include <uvm/uvm_extern.h>
54 
55 extern char *extiobase;
56 extern int *nofault;
57 
58 /* ARGSUSED */
59 int
60 bus_space_map(t, bpa, size, flags, bshp)
61 	bus_space_tag_t t;
62 	bus_addr_t bpa;
63 	bus_size_t size;
64 	int flags;
65 	bus_space_handle_t *bshp;
66 {
67 	u_long kva;
68 	int error;
69 
70 	if (t == HP300_BUS_SPACE_INTIO) {
71 		/*
72 		 * Intio space is direct-mapped in pmap_bootstrap(); just
73 		 * do the translation.
74 		 */
75 		*bshp = (bus_space_handle_t)IIOV(INTIOBASE + bpa);
76 		return (0);
77 	}
78 
79 	if (t != HP300_BUS_SPACE_DIO)
80 		panic("bus_space_map: bad space tag");
81 
82 	/*
83 	 * Allocate virtual address space from the extio extent map.
84 	 */
85 	size = m68k_round_page(size);
86 	error = extent_alloc(extio_ex, size, PAGE_SIZE, 0,
87 	    EX_FAST | EX_NOWAIT | (extio_ex_malloc_safe ? EX_MALLOCOK : 0),
88 	    &kva);
89 	if (error)
90 		return (error);
91 
92 	/*
93 	 * Map the range.  The range is always cache-inhibited on the hp300.
94 	 */
95 	physaccess((caddr_t)kva, (caddr_t)bpa, size, PG_RW|PG_CI);
96 
97 	/*
98 	 * All done.
99 	 */
100 	*bshp = (bus_space_handle_t)kva;
101 	return (0);
102 }
103 
104 /* ARGSUSED */
105 int
106 bus_space_alloc(t, rstart, rend, size, alignment, boundary, flags,
107     bpap, bshp)
108 	bus_space_tag_t t;
109 	bus_addr_t rstart, rend;
110 	bus_size_t size, alignment, boundary;
111 	int flags;
112 	bus_addr_t *bpap;
113 	bus_space_handle_t *bshp;
114 {
115 
116 	/*
117 	 * Not meaningful on any currently-supported hp300 bus.
118 	 */
119 	return (EINVAL);
120 }
121 
122 /* ARGSUSED */
123 void
124 bus_space_free(t, bsh, size)
125 	bus_space_tag_t t;
126 	bus_space_handle_t bsh;
127 	bus_size_t size;
128 {
129 
130 	/*
131 	 * Not meaningful on any currently-supported hp300 bus.
132 	 */
133 	panic("bus_space_free: shouldn't be here");
134 }
135 
136 void
137 bus_space_unmap(t, bsh, size)
138 	bus_space_tag_t t;
139 	bus_space_handle_t bsh;
140 	bus_size_t size;
141 {
142 
143 	if (t == HP300_BUS_SPACE_INTIO) {
144 		/*
145 		 * Intio space is direct-mapped in pmap_bootstrap(); nothing
146 		 * to do
147 		 */
148 		return;
149 	}
150 
151 	if (t != HP300_BUS_SPACE_DIO)
152 		panic("bus_space_map: bad space tag");
153 
154 	size = m68k_round_page(size);
155 
156 #ifdef DIAGNOSTIC
157 	if (bsh & PGOFSET)
158 		panic("bus_space_unmap: unaligned");
159 	if ((caddr_t)bsh < extiobase ||
160 	    (caddr_t)bsh >= (extiobase + ptoa(EIOMAPSIZE)))
161 		panic("bus_space_unmap: bad bus space handle");
162 #endif
163 
164 	/*
165 	 * Unmap the range.
166 	 */
167 	physunaccess((caddr_t)bsh, size);
168 
169 	/*
170 	 * Free it from the extio extent map.
171 	 */
172 	if (extent_free(extio_ex, (u_long) bsh, size,
173 	    EX_NOWAIT | (extio_ex_malloc_safe ? EX_MALLOCOK : 0)))
174 		printf("bus_space_unmap: kva 0x%lx size 0x%lx: "
175 		    "can't free region\n", (u_long) bsh, size);
176 }
177 
178 /* ARGSUSED */
179 int
180 bus_space_subregion(t, bsh, offset, size, nbshp)
181 	bus_space_tag_t t;
182 	bus_space_handle_t bsh;
183 	bus_size_t offset, size;
184 	bus_space_handle_t *nbshp;
185 {
186 
187 	*nbshp = bsh + offset;
188 	return (0);
189 }
190 
191 /* ARGSUSED */
192 int
193 hp300_bus_space_probe(t, bsh, offset, sz)
194 	bus_space_tag_t t;
195 	bus_space_handle_t bsh;
196 	bus_size_t offset;
197 	int sz;
198 {
199 	label_t faultbuf;
200 	int i;
201 
202 	nofault = (int *)&faultbuf;
203 	if (setjmp((label_t *)nofault)) {
204 		nofault = NULL;
205 		return (0);
206 	}
207 
208 	switch (sz) {
209 	case 1:
210 		i = bus_space_read_1(t, bsh, offset);
211 		break;
212 
213 	case 2:
214 		i = bus_space_read_2(t, bsh, offset);
215 		break;
216 
217 	case 4:
218 		i = bus_space_read_4(t, bsh, offset);
219 		break;
220 
221 	default:
222 		panic("bus_space_probe: unupported data size %d", sz);
223 		/* NOTREACHED */
224 	}
225 
226 	nofault = NULL;
227 	return (1);
228 }
229