Home | History | Annotate | Line # | Download | only in imx
imx_space.c revision 1.4
      1 /* $Id: imx_space.c,v 1.4 2012/09/01 00:06:54 matt Exp $ */
      2 
      3 /* derived from: */
      4 /*	$NetBSD: imx_space.c,v 1.4 2012/09/01 00:06:54 matt 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 <sys/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 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
    167 	/* read (single) */
    168 	generic_bs_r_1,
    169 	generic_armv4_bs_r_2,
    170 	generic_bs_r_4,
    171 	bs_notimpl_bs_r_8,
    172 
    173 	/* read multiple */
    174 	generic_bs_rm_1,
    175 	generic_armv4_bs_rm_2,
    176 	generic_bs_rm_4,
    177 	bs_notimpl_bs_rm_8,
    178 
    179 	/* read region */
    180 	generic_bs_rr_1,
    181 	generic_armv4_bs_rr_2,
    182 	generic_bs_rr_4,
    183 	bs_notimpl_bs_rr_8,
    184 
    185 	/* write (single) */
    186 	generic_bs_w_1,
    187 	generic_armv4_bs_w_2,
    188 	generic_bs_w_4,
    189 	bs_notimpl_bs_w_8,
    190 
    191 	/* write multiple */
    192 	generic_bs_wm_1,
    193 	generic_armv4_bs_wm_2,
    194 	generic_bs_wm_4,
    195 	bs_notimpl_bs_wm_8,
    196 
    197 	/* write region */
    198 	generic_bs_wr_1,
    199 	generic_armv4_bs_wr_2,
    200 	generic_bs_wr_4,
    201 	bs_notimpl_bs_wr_8,
    202 #endif
    203 };
    204 
    205 int
    206 imx_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
    207 	      int flag, bus_space_handle_t *bshp)
    208 {
    209 	u_long startpa, endpa, pa;
    210 	vaddr_t va;
    211 	pt_entry_t *pte;
    212 	const struct pmap_devmap	*pd;
    213 
    214 	if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
    215 		/* Device was statically mapped. */
    216 		*bshp = pd->pd_va + (bpa - pd->pd_pa);
    217 		return 0;
    218 	}
    219 
    220 	startpa = trunc_page(bpa);
    221 	endpa = round_page(bpa + size);
    222 
    223 	/* XXX use extent manager to check duplicate mapping */
    224 
    225 	va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
    226 	    UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
    227 	if (! va)
    228 		return(ENOMEM);
    229 
    230 	*bshp = (bus_space_handle_t)(va + (bpa - startpa));
    231 
    232 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    233 		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE,
    234 		    (flag & BUS_SPACE_MAP_CACHEABLE) ? 0 : PMAP_NOCACHE);
    235 	}
    236 	pmap_update(pmap_kernel());
    237 
    238 	return(0);
    239 }
    240 
    241 void
    242 imx_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    243 {
    244 	vaddr_t	va;
    245 	vsize_t	sz;
    246 
    247 	if (pmap_devmap_find_va(bsh, size) != NULL) {
    248 		/* Device was statically mapped; nothing to do. */
    249 		return;
    250 	}
    251 
    252 	va = trunc_page(bsh);
    253 	sz = round_page(bsh + size) - va;
    254 
    255 	pmap_kremove(va, sz);
    256 	pmap_update(pmap_kernel());
    257 	uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY);
    258 }
    259 
    260 
    261 int
    262 imx_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
    263     bus_size_t size, bus_space_handle_t *nbshp)
    264 {
    265 
    266 	*nbshp = bsh + offset;
    267 	return (0);
    268 }
    269 
    270 void
    271 imx_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
    272     bus_size_t len, int flags)
    273 {
    274 
    275 	/* Nothing to do. */
    276 }
    277 
    278 void *
    279 imx_bs_vaddr(void *t, bus_space_handle_t bsh)
    280 {
    281 
    282 	return ((void *)bsh);
    283 }
    284 
    285 
    286 int
    287 imx_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
    288     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
    289     bus_addr_t *bpap, bus_space_handle_t *bshp)
    290 {
    291 
    292 	panic("imx_io_bs_alloc(): not implemented\n");
    293 }
    294 
    295 void
    296 imx_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    297 {
    298 
    299 	panic("imx_io_bs_free(): not implemented\n");
    300 }
    301 
    302 
    303