Home | History | Annotate | Line # | Download | only in xscale
ixp425_space.c revision 1.4
      1 /*	$NetBSD: ixp425_space.c,v 1.4 2005/04/01 11:59:25 yamt 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.4 2005/04/01 11:59:25 yamt 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, UVM_KMF_VAONLY);
    161 	if (va == 0)
    162 		return ENOMEM;
    163 
    164 	/* Store the bus space handle */
    165 	*bshp = va + offset;
    166 
    167 	/* Now map the pages */
    168 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    169 		pmap_enter(pmap_kernel(), va, pa,
    170 		    VM_PROT_READ | VM_PROT_WRITE,
    171 		    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
    172 	}
    173 	pmap_update(pmap_kernel());
    174 
    175 	return(0);
    176 }
    177 
    178 void
    179 ixp425_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    180 {
    181 	vaddr_t	va;
    182 	vaddr_t	endva;
    183 
    184 	if (pmap_devmap_find_va(bsh, size) != NULL) {
    185 		/* Device was statically mapped; nothing to do. */
    186 		return;
    187 	}
    188 
    189 	endva = round_page(bsh + size);
    190 	va = trunc_page(bsh);
    191 
    192 	pmap_remove(pmap_kernel(), va, endva);
    193 	pmap_update(pmap_kernel());
    194 	uvm_km_free(kernel_map, va, endva - va, UVM_KMF_VAONLY);
    195 }
    196 
    197 int
    198 ixp425_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
    199 	bus_size_t size, bus_size_t alignment, bus_size_t boundary, int cacheable,
    200 	bus_addr_t *bpap, bus_space_handle_t *bshp)
    201 {
    202 	panic("ixp425_bs_alloc(): not implemented\n");
    203 }
    204 
    205 void
    206 ixp425_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    207 {
    208 	panic("ixp425_bs_free(): not implemented\n");
    209 }
    210 
    211 int
    212 ixp425_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
    213 	bus_size_t size, bus_space_handle_t *nbshp)
    214 {
    215 	*nbshp = bsh + offset;
    216 	return (0);
    217 }
    218 
    219 void *
    220 ixp425_bs_vaddr(void *t, bus_space_handle_t bsh)
    221 {
    222 	return ((void *)bsh);
    223 }
    224 
    225 paddr_t
    226 ixp425_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
    227 {
    228 	/* Not supported. */
    229 	return (-1);
    230 }
    231 
    232 void
    233 ixp425_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
    234     bus_size_t len, int flags)
    235 {
    236 /* NULL */
    237 }
    238 /* End of ixp425_space.c */
    239