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