Home | History | Annotate | Line # | Download | only in imx
imx_space.c revision 1.2.2.2
      1 /* $Id: imx_space.c,v 1.2.2.2 2010/11/15 14:38:22 uebayasi Exp $ */
      2 
      3 /* derived from: */
      4 /*	$NetBSD: imx_space.c,v 1.2.2.2 2010/11/15 14:38:22 uebayasi Exp $ */
      5 
      6 /*
      7  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
      8  * All rights reserved.
      9  *
     10  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed for the NetBSD Project by
     23  *	Wasabi Systems, Inc.
     24  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     25  *    or promote products derived from this software without specific prior
     26  *    written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38  * POSSIBILITY OF SUCH DAMAGE.
     39  */
     40 /*
     41  * Copyright (c) 1997 Mark Brinicombe.
     42  * Copyright (c) 1997 Causality Limited.
     43  * All rights reserved.
     44  *
     45  * This code is derived from software contributed to The NetBSD Foundation
     46  * by Ichiro FUKUHARA.
     47  *
     48  * Redistribution and use in source and binary forms, with or without
     49  * modification, are permitted provided that the following conditions
     50  * are met:
     51  * 1. Redistributions of source code must retain the above copyright
     52  *    notice, this list of conditions and the following disclaimer.
     53  * 2. Redistributions in binary form must reproduce the above copyright
     54  *    notice, this list of conditions and the following disclaimer in the
     55  *    documentation and/or other materials provided with the distribution.
     56  * 3. All advertising materials mentioning features or use of this software
     57  *    must display the following acknowledgement:
     58  *	This product includes software developed by Mark Brinicombe.
     59  * 4. The name of the company nor the name of the author may be used to
     60  *    endorse or promote products derived from this software without specific
     61  *    prior written permission.
     62  *
     63  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     64  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     65  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     66  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     67  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     68  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     69  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  * SUCH DAMAGE.
     74  */
     75 
     76 /*
     77  * bus_space(9) support for Freescale iMX31 processor
     78  */
     79 
     80 #include <sys/param.h>
     81 #include <sys/systm.h>
     82 #include <uvm/uvm_extern.h>
     83 #include <machine/bus.h>
     84 
     85 bs_protos(imx);
     86 bs_protos(generic);
     87 bs_protos(generic_armv4);
     88 bs_protos(bs_notimpl);
     89 
     90 struct bus_space imx_bs_tag = {
     91 	/* cookie */
     92 	(void *) 0,
     93 
     94 	/* mapping/unmapping */
     95 	imx_bs_map,
     96 	imx_bs_unmap,
     97 	imx_bs_subregion,
     98 
     99 	/* allocation/deallocation */
    100 	imx_bs_alloc,	/* not implemented */
    101 	imx_bs_free,		/* not implemented */
    102 
    103 	/* get kernel virtual address */
    104 	imx_bs_vaddr,
    105 
    106 	/* mmap */
    107 	bs_notimpl_bs_mmap,
    108 
    109 	/* barrier */
    110 	imx_bs_barrier,
    111 
    112 	/* read (single) */
    113 	generic_bs_r_1,
    114 	generic_armv4_bs_r_2,
    115 	generic_bs_r_4,
    116 	bs_notimpl_bs_r_8,
    117 
    118 	/* read multiple */
    119 	generic_bs_rm_1,
    120 	generic_armv4_bs_rm_2,
    121 	generic_bs_rm_4,
    122 	bs_notimpl_bs_rm_8,
    123 
    124 	/* read region */
    125 	generic_bs_rr_1,
    126 	generic_armv4_bs_rr_2,
    127 	generic_bs_rr_4,
    128 	bs_notimpl_bs_rr_8,
    129 
    130 	/* write (single) */
    131 	generic_bs_w_1,
    132 	generic_armv4_bs_w_2,
    133 	generic_bs_w_4,
    134 	bs_notimpl_bs_w_8,
    135 
    136 	/* write multiple */
    137 	generic_bs_wm_1,
    138 	generic_armv4_bs_wm_2,
    139 	generic_bs_wm_4,
    140 	bs_notimpl_bs_wm_8,
    141 
    142 	/* write region */
    143 	generic_bs_wr_1,
    144 	generic_armv4_bs_wr_2,
    145 	generic_bs_wr_4,
    146 	bs_notimpl_bs_wr_8,
    147 
    148 	/* set multiple */
    149 	bs_notimpl_bs_sm_1,
    150 	bs_notimpl_bs_sm_2,
    151 	bs_notimpl_bs_sm_4,
    152 	bs_notimpl_bs_sm_8,
    153 
    154 	/* set region */
    155 	generic_bs_sr_1,
    156 	generic_armv4_bs_sr_2,
    157 	bs_notimpl_bs_sr_4,
    158 	bs_notimpl_bs_sr_8,
    159 
    160 	/* copy */
    161 	bs_notimpl_bs_c_1,
    162 	generic_armv4_bs_c_2,
    163 	bs_notimpl_bs_c_4,
    164 	bs_notimpl_bs_c_8,
    165 };
    166 
    167 int
    168 imx_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
    169 	      int flag, bus_space_handle_t *bshp)
    170 {
    171 	u_long startpa, endpa, pa;
    172 	vaddr_t va;
    173 	pt_entry_t *pte;
    174 	const struct pmap_devmap	*pd;
    175 
    176 	if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
    177 		/* Device was statically mapped. */
    178 		*bshp = pd->pd_va + (bpa - pd->pd_pa);
    179 		return 0;
    180 	}
    181 
    182 	startpa = trunc_page(bpa);
    183 	endpa = round_page(bpa + size);
    184 
    185 	/* XXX use extent manager to check duplicate mapping */
    186 
    187 	va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
    188 	    UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
    189 	if (! va)
    190 		return(ENOMEM);
    191 
    192 	*bshp = (bus_space_handle_t)(va + (bpa - startpa));
    193 
    194 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    195 		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, 0);
    196 		if ((flag & BUS_SPACE_MAP_CACHEABLE) == 0) {
    197 			pte = vtopte(va);
    198 			*pte &= ~L2_S_CACHE_MASK;
    199 			PTE_SYNC(pte);
    200 			/* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
    201 			 *      waste.
    202 			 */
    203 		}
    204 	}
    205 	pmap_update(pmap_kernel());
    206 
    207 	return(0);
    208 }
    209 
    210 void
    211 imx_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    212 {
    213 	vaddr_t	va;
    214 	vsize_t	sz;
    215 
    216 	if (pmap_devmap_find_va(bsh, size) != NULL) {
    217 		/* Device was statically mapped; nothing to do. */
    218 		return;
    219 	}
    220 
    221 	va = trunc_page(bsh);
    222 	sz = round_page(bsh + size) - va;
    223 
    224 	pmap_kremove(va, sz);
    225 	pmap_update(pmap_kernel());
    226 	uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY);
    227 }
    228 
    229 
    230 int
    231 imx_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
    232     bus_size_t size, bus_space_handle_t *nbshp)
    233 {
    234 
    235 	*nbshp = bsh + offset;
    236 	return (0);
    237 }
    238 
    239 void
    240 imx_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
    241     bus_size_t len, int flags)
    242 {
    243 
    244 	/* Nothing to do. */
    245 }
    246 
    247 void *
    248 imx_bs_vaddr(void *t, bus_space_handle_t bsh)
    249 {
    250 
    251 	return ((void *)bsh);
    252 }
    253 
    254 
    255 int
    256 imx_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
    257     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
    258     bus_addr_t *bpap, bus_space_handle_t *bshp)
    259 {
    260 
    261 	panic("imx_io_bs_alloc(): not implemented\n");
    262 }
    263 
    264 void
    265 imx_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    266 {
    267 
    268 	panic("imx_io_bs_free(): not implemented\n");
    269 }
    270 
    271 
    272