1205354Simp/* $NetBSD: s3c2xx0_space.c,v 1.7 2005/11/24 13:08:32 yamt Exp $ */ 2205354Simp 3205354Simp/* 4205354Simp * Copyright (c) 2002 Fujitsu Component Limited 5205354Simp * Copyright (c) 2002 Genetec Corporation 6205354Simp * All rights reserved. 7205354Simp * 8205354Simp * Redistribution and use in source and binary forms, with or without 9205354Simp * modification, are permitted provided that the following conditions 10205354Simp * are met: 11205354Simp * 1. Redistributions of source code must retain the above copyright 12205354Simp * notice, this list of conditions and the following disclaimer. 13205354Simp * 2. Redistributions in binary form must reproduce the above copyright 14205354Simp * notice, this list of conditions and the following disclaimer in the 15205354Simp * documentation and/or other materials provided with the distribution. 16205354Simp * 3. Neither the name of The Fujitsu Component Limited nor the name of 17205354Simp * Genetec corporation may not be used to endorse or promote products 18205354Simp * derived from this software without specific prior written permission. 19205354Simp * 20205354Simp * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC 21205354Simp * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 22205354Simp * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23205354Simp * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24205354Simp * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC 25205354Simp * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26205354Simp * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27205354Simp * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 28205354Simp * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29205354Simp * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30205354Simp * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31205354Simp * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32205354Simp * SUCH DAMAGE. 33205354Simp */ 34205354Simp/* derived from sa11x0_io.c */ 35205354Simp 36205354Simp/* 37205354Simp * Copyright (c) 1997 Mark Brinicombe. 38205354Simp * Copyright (c) 1997 Causality Limited. 39205354Simp * All rights reserved. 40205354Simp * 41205354Simp * This code is derived from software contributed to The NetBSD Foundation 42205354Simp * by Ichiro FUKUHARA. 43205354Simp * 44205354Simp * Redistribution and use in source and binary forms, with or without 45205354Simp * modification, are permitted provided that the following conditions 46205354Simp * are met: 47205354Simp * 1. Redistributions of source code must retain the above copyright 48205354Simp * notice, this list of conditions and the following disclaimer. 49205354Simp * 2. Redistributions in binary form must reproduce the above copyright 50205354Simp * notice, this list of conditions and the following disclaimer in the 51205354Simp * documentation and/or other materials provided with the distribution. 52205354Simp * 3. All advertising materials mentioning features or use of this software 53205354Simp * must display the following acknowledgement: 54205354Simp * This product includes software developed by Mark Brinicombe. 55205354Simp * 4. The name of the company nor the name of the author may be used to 56205354Simp * endorse or promote products derived from this software without specific 57205354Simp * prior written permission. 58205354Simp * 59205354Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 60205354Simp * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 61205354Simp * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 62205354Simp * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 63205354Simp * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 64205354Simp * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 65205354Simp * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66205354Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67205354Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68205354Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69205354Simp * SUCH DAMAGE. 70205354Simp */ 71205354Simp 72205354Simp/* 73205354Simp * bus_space functions for Samsung S3C2800/2400/2410. 74205354Simp */ 75205354Simp 76205354Simp#include <sys/cdefs.h> 77205354Simp__FBSDID("$FreeBSD$"); 78205354Simp 79205354Simp#include <sys/param.h> 80205354Simp#include <sys/systm.h> 81205354Simp#include <sys/bus.h> 82205354Simp 83205354Simp#include <vm/vm.h> 84205354Simp#include <vm/vm_kern.h> 85205354Simp#include <vm/pmap.h> 86205354Simp#include <vm/vm_page.h> 87205354Simp#include <vm/vm_extern.h> 88205354Simp 89205354Simp#include <machine/bus.h> 90205354Simp 91205354Simp/* Prototypes for all the bus_space structure functions */ 92205354Simpbs_protos(s3c2xx0); 93205354Simpbs_protos(generic); 94205354Simpbs_protos(generic_armv4); 95205354Simp 96205354Simpstruct bus_space s3c2xx0_bs_tag = { 97205354Simp /* cookie */ 98205354Simp (void *) 0, 99205354Simp 100205354Simp /* mapping/unmapping */ 101205354Simp s3c2xx0_bs_map, 102205354Simp s3c2xx0_bs_unmap, 103205354Simp s3c2xx0_bs_subregion, 104205354Simp 105205354Simp /* allocation/deallocation */ 106205354Simp s3c2xx0_bs_alloc, /* not implemented */ 107205354Simp s3c2xx0_bs_free, /* not implemented */ 108205354Simp 109205354Simp /* barrier */ 110205354Simp s3c2xx0_bs_barrier, 111205354Simp 112205354Simp /* read (single) */ 113205354Simp generic_bs_r_1, 114205354Simp generic_armv4_bs_r_2, 115205354Simp generic_bs_r_4, 116205354Simp NULL, 117205354Simp 118205354Simp /* read multiple */ 119205354Simp generic_bs_rm_1, 120205354Simp generic_armv4_bs_rm_2, 121205354Simp generic_bs_rm_4, 122205354Simp NULL, 123205354Simp 124205354Simp /* read region */ 125205354Simp generic_bs_rr_1, 126205354Simp generic_armv4_bs_rr_2, 127205354Simp generic_bs_rr_4, 128205354Simp NULL, 129205354Simp 130205354Simp /* write (single) */ 131205354Simp generic_bs_w_1, 132205354Simp generic_armv4_bs_w_2, 133205354Simp generic_bs_w_4, 134205354Simp NULL, 135205354Simp 136205354Simp /* write multiple */ 137205354Simp generic_bs_wm_1, 138205354Simp generic_armv4_bs_wm_2, 139205354Simp generic_bs_wm_4, 140205354Simp NULL, 141205354Simp 142205354Simp /* write region */ 143205354Simp generic_bs_wr_1, 144205354Simp generic_armv4_bs_wr_2, 145205354Simp generic_bs_wr_4, 146205354Simp NULL, 147205354Simp 148205354Simp /* set multiple */ 149205354Simp NULL, 150205354Simp NULL, 151205354Simp NULL, 152205354Simp NULL, 153205354Simp 154205354Simp /* set region */ 155205354Simp generic_bs_sr_1, 156205354Simp generic_armv4_bs_sr_2, 157205354Simp NULL, 158205354Simp NULL, 159205354Simp 160205354Simp /* copy */ 161205354Simp NULL, 162205354Simp generic_armv4_bs_c_2, 163205354Simp NULL, 164205354Simp NULL, 165205354Simp}; 166205354Simp 167205354Simpint 168205354Simps3c2xx0_bs_map(void *t, bus_addr_t bpa, bus_size_t size, 169205354Simp int flag, bus_space_handle_t * bshp) 170205354Simp{ 171205354Simp u_long startpa, endpa, pa; 172205354Simp vm_offset_t va; 173205354Simp pt_entry_t *pte; 174205354Simp const struct pmap_devmap *pd; 175205354Simp 176205354Simp if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { 177205354Simp /* Device was statically mapped. */ 178205354Simp *bshp = pd->pd_va + (bpa - pd->pd_pa); 179205354Simp return 0; 180205354Simp } 181205354Simp 182205354Simp startpa = trunc_page(bpa); 183205354Simp endpa = round_page(bpa + size); 184205354Simp 185210396Sandrew va = kmem_alloc_nofault(kernel_map, endpa - startpa); 186205354Simp if (!va) 187205354Simp return (ENOMEM); 188205354Simp 189205354Simp *bshp = (bus_space_handle_t) (va + (bpa - startpa)); 190205354Simp 191205354Simp for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { 192205354Simp pmap_kenter(va, pa); 193205354Simp pte = vtopte(va); 194205354Simp if ((flag & BUS_SPACE_MAP_CACHEABLE) == 0) 195205354Simp *pte &= ~L2_S_CACHE_MASK; 196205354Simp } 197205354Simp return (0); 198205354Simp} 199205354Simp 200205354Simpvoid 201205354Simps3c2xx0_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size) 202205354Simp{ 203205354Simp vm_offset_t va, endva; 204205354Simp 205205354Simp if (pmap_devmap_find_va((vm_offset_t)t, size) != NULL) { 206205354Simp /* Device was statically mapped; nothing to do. */ 207205354Simp return; 208205354Simp } 209205354Simp 210205354Simp endva = round_page((vm_offset_t)t + size); 211205354Simp va = trunc_page((vm_offset_t)t); 212205354Simp 213205354Simp while (va < endva) { 214205354Simp pmap_kremove(va); 215205354Simp va += PAGE_SIZE; 216205354Simp } 217205354Simp kmem_free(kernel_map, va, endva - va); 218205354Simp} 219205354Simp 220205354Simpint 221205354Simps3c2xx0_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, 222205354Simp bus_size_t size, bus_space_handle_t * nbshp) 223205354Simp{ 224205354Simp 225205354Simp *nbshp = bsh + offset; 226205354Simp return (0); 227205354Simp} 228205354Simp 229205354Simpvoid 230205354Simps3c2xx0_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, 231205354Simp bus_size_t len, int flags) 232205354Simp{ 233205354Simp 234205354Simp /* Nothing to do. */ 235205354Simp} 236205354Simp 237205354Simpint 238205354Simps3c2xx0_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, 239205354Simp bus_size_t size, bus_size_t alignment, bus_size_t boundary, 240205354Simp int flags, bus_addr_t * bpap, bus_space_handle_t * bshp) 241205354Simp{ 242205354Simp 243205354Simp panic("s3c2xx0_io_bs_alloc(): not implemented\n"); 244205354Simp} 245205354Simp 246205354Simpvoid 247205354Simps3c2xx0_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) 248205354Simp{ 249205354Simp panic("s3c2xx0_io_bs_free(): not implemented\n"); 250205354Simp} 251