obio_space.c revision 1.2
1/* $NetBSD: obio_space.c,v 1.2 2002/03/19 01:36:13 briggs Exp $ */ 2 3/* 4 * Copyright (c) 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38/* 39 * bus_space functions for IQ80310 on-board devices 40 */ 41 42#include <sys/param.h> 43#include <sys/systm.h> 44 45#include <uvm/uvm_extern.h> 46 47#include <machine/bus.h> 48 49#include "iq80310reg.h" 50 51/* Prototypes for all the bus_space structure functions */ 52bs_protos(obio); 53bs_protos(bs_notimpl); 54 55/* 56 * The obio bus space tag. This is constant for all instances, so 57 * we never have to explicitly "create" it. 58 */ 59struct bus_space obio_bs_tag = { 60 /* cookie */ 61 (void *) 0, 62 63 /* mapping/unmapping */ 64 obio_bs_map, 65 obio_bs_unmap, 66 obio_bs_subregion, 67 68 /* allocation/deallocation */ 69 obio_bs_alloc, 70 obio_bs_free, 71 72 /* get kernel virtual address */ 73 obio_bs_vaddr, 74 75 /* mmap */ 76 bs_notimpl_bs_mmap, 77 78 /* barrier */ 79 obio_bs_barrier, 80 81 /* read (single) */ 82 obio_bs_r_1, 83 bs_notimpl_bs_r_2, 84 obio_bs_r_4, 85 bs_notimpl_bs_r_8, 86 87 /* read multiple */ 88 obio_bs_rm_1, 89 bs_notimpl_bs_rm_2, 90 bs_notimpl_bs_rm_4, 91 bs_notimpl_bs_rm_8, 92 93 /* read region */ 94 obio_bs_rr_1, 95 bs_notimpl_bs_rr_2, 96 bs_notimpl_bs_rr_4, 97 bs_notimpl_bs_rr_8, 98 99 /* write (single) */ 100 obio_bs_w_1, 101 bs_notimpl_bs_w_2, 102 obio_bs_w_4, 103 bs_notimpl_bs_w_8, 104 105 /* write multiple */ 106 obio_bs_wm_1, 107 bs_notimpl_bs_wm_2, 108 bs_notimpl_bs_wm_4, 109 bs_notimpl_bs_wm_8, 110 111 /* write region */ 112 bs_notimpl_bs_wr_1, 113 bs_notimpl_bs_wr_2, 114 bs_notimpl_bs_wr_4, 115 bs_notimpl_bs_wr_8, 116 117 /* set multiple */ 118 bs_notimpl_bs_sm_1, 119 bs_notimpl_bs_sm_2, 120 bs_notimpl_bs_sm_4, 121 bs_notimpl_bs_sm_8, 122 123 /* set region */ 124 bs_notimpl_bs_sr_1, 125 bs_notimpl_bs_sr_2, 126 bs_notimpl_bs_sr_4, 127 bs_notimpl_bs_sr_8, 128 129 /* copy */ 130 bs_notimpl_bs_c_1, 131 bs_notimpl_bs_c_2, 132 bs_notimpl_bs_c_4, 133 bs_notimpl_bs_c_8, 134}; 135 136int 137obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags, 138 bus_space_handle_t *bshp) 139{ 140 u_long startpa, endpa, pa; 141 vaddr_t va; 142 pt_entry_t *pte; 143 144 if (bpa > IQ80310_OBIO_BASE) { 145 146 /* 147 * IQ80310 on-board devices are mapped VA==PA. All addresses 148 * we're provided, therefore, don't need any additional mapping. 149 */ 150 *bshp = bpa; 151 152 } else { 153 154 /* 155 * Some devices actually lie outside the range above. 156 * Notably: flash. 157 */ 158 startpa = trunc_page(bpa); 159 endpa = round_page(bpa + size); 160 161 /* XXX use extent manager to check duplicate mapping */ 162 163 va = uvm_km_valloc(kernel_map, endpa - startpa); 164 if (! va) 165 return(ENOMEM); 166 167 *bshp = (bus_space_handle_t)(va + (bpa - startpa)); 168 169 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { 170 pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); 171 pte = pmap_pte(pmap_kernel(), va); 172 *pte &= ~PT_CACHEABLE; 173 } 174 pmap_update(pmap_kernel()); 175 176 } 177 178 return 0; 179} 180 181int 182obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size, 183 bus_size_t alignment, bus_size_t boundary, int flags, bus_addr_t *bpap, 184 bus_space_handle_t *bshp) 185{ 186 187 panic("obio_bs_alloc(): not implemented\n"); 188} 189 190 191void 192obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) 193{ 194 195 /* Nothing to do. */ 196 /* XXX -- technically, if we alloc and map above, we should 197 * unmap and free here, but we bail on this for now. 198 */ 199} 200 201void 202obio_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) 203{ 204 205 panic("obio_bs_free(): not implemented\n"); 206} 207 208int 209obio_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, 210 bus_size_t size, bus_space_handle_t *nbshp) 211{ 212 213 *nbshp = bsh + offset; 214 return (0); 215} 216 217void * 218obio_bs_vaddr(void *t, bus_space_handle_t bsh) 219{ 220 221 return ((void *)bsh); 222} 223 224void 225obio_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, 226 bus_size_t len, int flags) 227{ 228 229 /* Nothing to do. */ 230} 231