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