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