ixp425_space.c revision 1.3
1/* $NetBSD: ixp425_space.c,v 1.3 2003/11/16 12:41:03 scw Exp $ */ 2 3/* 4 * Copyright (c) 2003 5 * Ichiro FUKUHARA <ichiro@ichiro.org>. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Ichiro FUKUHARA. 19 * 4. The name of the company nor the name of the author may be used to 20 * endorse or promote products derived from this software without specific 21 * prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR 27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36#include <sys/cdefs.h> 37__KERNEL_RCSID(0, "$NetBSD: ixp425_space.c,v 1.3 2003/11/16 12:41:03 scw Exp $"); 38 39/* 40 * bus_space I/O functions for ixp425 41 */ 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/queue.h> 46 47#include <uvm/uvm.h> 48 49#include <machine/bus.h> 50 51#include <arm/xscale/ixp425reg.h> 52#include <arm/xscale/ixp425var.h> 53 54/* Proto types for all the bus_space structure functions */ 55bs_protos(ixp425); 56bs_protos(generic); 57bs_protos(generic_armv4); 58bs_protos(bs_notimpl); 59 60struct bus_space ixp425_bs_tag = { 61 /* cookie */ 62 (void *) 0, 63 64 /* mapping/unmapping */ 65 ixp425_bs_map, 66 ixp425_bs_unmap, 67 ixp425_bs_subregion, 68 69 /* allocation/deallocation */ 70 ixp425_bs_alloc, 71 ixp425_bs_free, 72 73 /* get kernel virtual address */ 74 ixp425_bs_vaddr, 75 76 /* mmap bus space for userland */ 77 ixp425_bs_mmap, 78 79 /* barrier */ 80 ixp425_bs_barrier, 81 82 /* read (single) */ 83 generic_bs_r_1, 84 generic_armv4_bs_r_2, 85 generic_bs_r_4, 86 bs_notimpl_bs_r_8, 87 88 /* read multiple */ 89 generic_bs_rm_1, 90 generic_armv4_bs_rm_2, 91 generic_bs_rm_4, 92 bs_notimpl_bs_rm_8, 93 94 /* read region */ 95 generic_bs_rr_1, 96 generic_armv4_bs_rr_2, 97 generic_bs_rr_4, 98 bs_notimpl_bs_rr_8, 99 100 /* write (single) */ 101 generic_bs_w_1, 102 generic_armv4_bs_w_2, 103 generic_bs_w_4, 104 bs_notimpl_bs_w_8, 105 106 /* write multiple */ 107 generic_bs_wm_1, 108 generic_armv4_bs_wm_2, 109 generic_bs_wm_4, 110 bs_notimpl_bs_wm_8, 111 112 /* write region */ 113 generic_bs_wr_1, 114 generic_armv4_bs_wr_2, 115 generic_bs_wr_4, 116 bs_notimpl_bs_wr_8, 117 118 /* set multiple */ 119 bs_notimpl_bs_sm_1, 120 bs_notimpl_bs_sm_2, 121 bs_notimpl_bs_sm_4, 122 bs_notimpl_bs_sm_8, 123 124 /* set region */ 125 bs_notimpl_bs_sr_1, 126 generic_armv4_bs_sr_2, 127 generic_bs_sr_4, 128 bs_notimpl_bs_sr_8, 129 130 /* copy */ 131 bs_notimpl_bs_c_1, 132 generic_armv4_bs_c_2, 133 bs_notimpl_bs_c_4, 134 bs_notimpl_bs_c_8, 135}; 136 137int 138ixp425_bs_map(void *t, bus_addr_t bpa, bus_size_t size, 139 int cacheable, bus_space_handle_t *bshp) 140{ 141 const struct pmap_devmap *pd; 142 143 paddr_t startpa; 144 paddr_t endpa; 145 paddr_t pa; 146 paddr_t offset; 147 vaddr_t va; 148 149 if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { 150 /* Device was statically mapped. */ 151 *bshp = pd->pd_va + (bpa - pd->pd_pa); 152 return 0; 153 } 154 155 endpa = round_page(bpa + size); 156 offset = bpa & PAGE_MASK; 157 startpa = trunc_page(bpa); 158 159 /* Get some VM. */ 160 if ((va = uvm_km_valloc(kernel_map, endpa - startpa)) == 0) 161 return ENOMEM; 162 163 /* Store the bus space handle */ 164 *bshp = va + offset; 165 166 /* Now map the pages */ 167 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { 168 pmap_enter(pmap_kernel(), va, pa, 169 VM_PROT_READ | VM_PROT_WRITE, 170 VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED); 171 } 172 pmap_update(pmap_kernel()); 173 174 return(0); 175} 176 177void 178ixp425_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) 179{ 180 vaddr_t va; 181 vaddr_t endva; 182 183 if (pmap_devmap_find_va(bsh, size) != NULL) { 184 /* Device was statically mapped; nothing to do. */ 185 return; 186 } 187 188 endva = round_page(bsh + size); 189 va = trunc_page(bsh); 190 191 uvm_km_free(kernel_map, va, endva - va); 192} 193 194int 195ixp425_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, 196 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int cacheable, 197 bus_addr_t *bpap, bus_space_handle_t *bshp) 198{ 199 panic("ixp425_bs_alloc(): not implemented\n"); 200} 201 202void 203ixp425_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) 204{ 205 panic("ixp425_bs_free(): not implemented\n"); 206} 207 208int 209ixp425_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 *nbshp = bsh + offset; 213 return (0); 214} 215 216void * 217ixp425_bs_vaddr(void *t, bus_space_handle_t bsh) 218{ 219 return ((void *)bsh); 220} 221 222paddr_t 223ixp425_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags) 224{ 225 /* Not supported. */ 226 return (-1); 227} 228 229void 230ixp425_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, 231 bus_size_t len, int flags) 232{ 233/* NULL */ 234} 235/* End of ixp425_space.c */ 236