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