1 /* $NetBSD: bus_space.c,v 1.2 2000/10/14 07:19:24 tsutsui 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 news68k. 41 * Just taken from hp300. 42 */ 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/map.h> 47 48 #include <machine/bus.h> 49 50 #include <uvm/uvm_extern.h> 51 52 extern caddr_t extiobase; 53 extern int *nofault; 54 55 /* ARGSUSED */ 56 int 57 bus_space_map(t, bpa, size, flags, bshp) 58 bus_space_tag_t t; 59 bus_addr_t bpa; 60 bus_size_t size; 61 int flags; 62 bus_space_handle_t *bshp; 63 { 64 65 if (t == NEWS68K_BUS_SPACE_INTIO) { 66 /* 67 * Intio space is direct-mapped in pmap_bootstrap(); just 68 * do the translation. 69 */ 70 *bshp = (bus_space_handle_t)IIOV(bpa); 71 return (0); 72 } 73 74 if (t == NEWS68K_BUS_SPACE_EIO) 75 *bshp = (bus_space_handle_t)bpa; /* XXX use tt0 mapping */ 76 return (0); 77 78 return (1); 79 } 80 81 /* ARGSUSED */ 82 int 83 bus_space_alloc(t, rstart, rend, size, alignment, boundary, flags, 84 bpap, bshp) 85 bus_space_tag_t t; 86 bus_addr_t rstart, rend; 87 bus_size_t size, alignment, boundary; 88 int flags; 89 bus_addr_t *bpap; 90 bus_space_handle_t *bshp; 91 { 92 93 /* 94 * Not meaningful on any currently-supported news68k bus. 95 */ 96 return (EINVAL); 97 } 98 99 /* ARGSUSED */ 100 void 101 bus_space_free(t, bsh, size) 102 bus_space_tag_t t; 103 bus_space_handle_t bsh; 104 bus_size_t size; 105 { 106 107 /* 108 * Not meaningful on any currently-supported news68k bus. 109 */ 110 panic("bus_space_free: shouldn't be here"); 111 } 112 113 void 114 bus_space_unmap(t, bsh, size) 115 bus_space_tag_t t; 116 bus_space_handle_t bsh; 117 bus_size_t size; 118 { 119 120 if (t == NEWS68K_BUS_SPACE_INTIO) { 121 /* 122 * Intio space is direct-mapped in pmap_bootstrap(); nothing 123 * to do 124 */ 125 return; 126 } 127 128 if (t != NEWS68K_BUS_SPACE_EIO) 129 panic("bus_space_map: bad space tag"); 130 131 return; 132 } 133 134 /* ARGSUSED */ 135 int 136 bus_space_subregion(t, bsh, offset, size, nbshp) 137 bus_space_tag_t t; 138 bus_space_handle_t bsh; 139 bus_size_t offset, size; 140 bus_space_handle_t *nbshp; 141 { 142 143 *nbshp = bsh + offset; 144 return (0); 145 } 146 147 /* ARGSUSED */ 148 int 149 news68k_bus_space_probe(t, bsh, offset, sz) 150 bus_space_tag_t t; 151 bus_space_handle_t bsh; 152 bus_size_t offset; 153 int sz; 154 { 155 label_t faultbuf; 156 int i; 157 158 nofault = (int *)&faultbuf; 159 if (setjmp((label_t *)nofault)) { 160 nofault = NULL; 161 return (0); 162 } 163 164 switch (sz) { 165 case 1: 166 i = bus_space_read_1(t, bsh, offset); 167 break; 168 169 case 2: 170 i = bus_space_read_2(t, bsh, offset); 171 break; 172 173 case 4: 174 i = bus_space_read_4(t, bsh, offset); 175 break; 176 177 default: 178 panic("bus_space_probe: unupported data size %d\n", sz); 179 /* NOTREACHED */ 180 } 181 182 nofault = NULL; 183 return (1); 184 } 185