Home | History | Annotate | Line # | Download | only in ixp12x0
ixp12x0_io.c revision 1.12
      1  1.12     dsl /*	$NetBSD: ixp12x0_io.c,v 1.12 2009/03/14 21:04:05 dsl 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.12     dsl __KERNEL_RCSID(0, "$NetBSD: ixp12x0_io.c,v 1.12 2009/03/14 21:04:05 dsl 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.8     igy 	ixp12x0_bs_map,
     66   1.8     igy 	ixp12x0_bs_unmap,
     67   1.1  ichiro 	ixp12x0_bs_subregion,
     68   1.1  ichiro 
     69   1.1  ichiro 	/* allocation/deallocation */
     70   1.8     igy 	ixp12x0_bs_alloc,
     71   1.8     igy 	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.8     igy 	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.8     igy 	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.8     igy 	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.8     igy /* Common routines */
    138   1.1  ichiro 
    139   1.8     igy int
    140   1.8     igy ixp12x0_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
    141   1.8     igy 	       int flags, bus_space_handle_t *bshp)
    142   1.1  ichiro {
    143   1.8     igy 	const struct pmap_devmap	*pd;
    144   1.1  ichiro 
    145   1.8     igy 	paddr_t		startpa;
    146   1.8     igy 	paddr_t		endpa;
    147   1.8     igy 	paddr_t		pa;
    148   1.8     igy 	paddr_t		offset;
    149   1.8     igy 	vaddr_t		va;
    150   1.8     igy 	pt_entry_t	*pte;
    151   1.8     igy 
    152   1.8     igy 	if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
    153   1.8     igy 		/* Device was statically mapped. */
    154   1.8     igy 		*bshp = pd->pd_va + (bpa - pd->pd_pa);
    155   1.8     igy 		return 0;
    156   1.8     igy 	}
    157   1.1  ichiro 
    158   1.3  ichiro 	endpa = round_page(bpa + size);
    159   1.8     igy 	offset = bpa & PAGE_MASK;
    160   1.8     igy 	startpa = trunc_page(bpa);
    161   1.8     igy 
    162  1.11    yamt 	va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
    163  1.11    yamt 	    UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
    164  1.10    yamt 	if (va  == 0)
    165   1.8     igy 		return ENOMEM;
    166   1.8     igy 
    167   1.8     igy 	*bshp = va + offset;
    168   1.8     igy 
    169   1.8     igy 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    170   1.8     igy 		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
    171   1.8     igy 		pte = vtopte(va);
    172   1.8     igy 		*pte &= ~L2_S_CACHE_MASK;
    173   1.8     igy 		PTE_SYNC(pte);
    174   1.1  ichiro 	}
    175   1.1  ichiro 	pmap_update(pmap_kernel());
    176   1.1  ichiro 
    177   1.8     igy 	return 0;
    178   1.1  ichiro }
    179   1.1  ichiro 
    180   1.1  ichiro void
    181   1.8     igy ixp12x0_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    182   1.1  ichiro {
    183   1.8     igy 	vaddr_t	va;
    184   1.8     igy 	vaddr_t	endva;
    185   1.8     igy 
    186   1.8     igy 	if (pmap_devmap_find_va(bsh, size) != NULL) {
    187   1.8     igy 		/* Device was statically mapped; nothing to do. */
    188   1.8     igy 		return;
    189   1.8     igy 	}
    190   1.1  ichiro 
    191   1.1  ichiro 	endva = round_page(bsh + size);
    192   1.8     igy 	va = trunc_page(bsh);
    193   1.1  ichiro 
    194   1.8     igy 	pmap_kremove(va, endva - va);
    195  1.10    yamt 	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.12     dsl ixp12x0_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    200   1.1  ichiro {
    201   1.1  ichiro 
    202   1.1  ichiro 	*nbshp = bsh + offset;
    203   1.1  ichiro 	return (0);
    204   1.1  ichiro }
    205   1.1  ichiro 
    206   1.1  ichiro void *
    207  1.12     dsl ixp12x0_bs_vaddr(void *t, bus_space_handle_t bsh)
    208   1.1  ichiro {
    209   1.1  ichiro 	return ((void *)bsh);
    210   1.1  ichiro }
    211   1.1  ichiro 
    212   1.8     igy int
    213   1.8     igy ixp12x0_bs_alloc(void *t,
    214   1.8     igy 		 bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
    215   1.8     igy 		 bus_size_t alignment, bus_size_t boundary,
    216   1.8     igy 		 int flags, bus_addr_t *bpap,
    217   1.8     igy 		 bus_space_handle_t *bshp)
    218   1.8     igy {
    219   1.8     igy 	panic("ixp12x0_bs_alloc(): not implemented\n");
    220   1.8     igy }
    221   1.8     igy 
    222   1.8     igy void
    223   1.8     igy ixp12x0_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    224   1.1  ichiro {
    225   1.8     igy 	panic("ixp12x0_bs_free(): not implemented\n");
    226   1.1  ichiro }
    227   1.1  ichiro 
    228   1.1  ichiro void
    229  1.12     dsl ixp12x0_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
    230   1.1  ichiro {
    231   1.1  ichiro /* NULL */
    232   1.1  ichiro }
    233   1.1  ichiro 
    234   1.1  ichiro /* End of ixp12x0_io.c */
    235