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