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