Home | History | Annotate | Line # | Download | only in xscale
ixp425_space.c revision 1.2
      1  1.2     scw /*	$NetBSD: ixp425_space.c,v 1.2 2003/10/23 09:25:44 scw Exp $ */
      2  1.1  ichiro 
      3  1.1  ichiro /*
      4  1.1  ichiro  * Copyright (c) 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.1  ichiro 
     36  1.1  ichiro #include <sys/cdefs.h>
     37  1.2     scw __KERNEL_RCSID(0, "$NetBSD: ixp425_space.c,v 1.2 2003/10/23 09:25:44 scw Exp $");
     38  1.1  ichiro 
     39  1.1  ichiro /*
     40  1.1  ichiro  * bus_space I/O functions for ixp425
     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/xscale/ixp425reg.h>
     52  1.1  ichiro #include <arm/xscale/ixp425var.h>
     53  1.1  ichiro 
     54  1.1  ichiro /* Proto types for all the bus_space structure functions */
     55  1.1  ichiro bs_protos(ixp425);
     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 ixp425_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.1  ichiro 	ixp425_bs_map,
     66  1.1  ichiro 	ixp425_bs_unmap,
     67  1.1  ichiro 	ixp425_bs_subregion,
     68  1.1  ichiro 
     69  1.1  ichiro 	/* allocation/deallocation */
     70  1.1  ichiro 	ixp425_bs_alloc,
     71  1.1  ichiro 	ixp425_bs_free,
     72  1.1  ichiro 
     73  1.1  ichiro 	/* get kernel virtual address */
     74  1.1  ichiro 	ixp425_bs_vaddr,
     75  1.1  ichiro 
     76  1.1  ichiro 	/* mmap bus space for userland */
     77  1.1  ichiro 	ixp425_bs_mmap,
     78  1.1  ichiro 
     79  1.1  ichiro 	/* barrier */
     80  1.1  ichiro 	ixp425_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.1  ichiro         bs_notimpl_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.1  ichiro         bs_notimpl_bs_wr_1,
    114  1.1  ichiro         generic_armv4_bs_wr_2,
    115  1.1  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.1  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.1  ichiro int
    138  1.1  ichiro ixp425_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
    139  1.1  ichiro 	      int cacheable, bus_space_handle_t *bshp)
    140  1.1  ichiro {
    141  1.1  ichiro 	const struct pmap_devmap	*pd;
    142  1.1  ichiro 
    143  1.1  ichiro 	paddr_t		startpa;
    144  1.1  ichiro         paddr_t		endpa;
    145  1.1  ichiro         paddr_t		pa;
    146  1.1  ichiro         paddr_t		offset;
    147  1.1  ichiro         vaddr_t		va;
    148  1.1  ichiro 
    149  1.1  ichiro 	if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
    150  1.1  ichiro 		/* Device was statically mapped. */
    151  1.1  ichiro 		*bshp = pd->pd_va + (bpa - pd->pd_pa);
    152  1.1  ichiro 		return 0;
    153  1.1  ichiro 	}
    154  1.1  ichiro 
    155  1.1  ichiro 	endpa = round_page(bpa + size);
    156  1.1  ichiro 	offset = bpa & PAGE_MASK;
    157  1.1  ichiro 	startpa = trunc_page(bpa);
    158  1.1  ichiro 
    159  1.1  ichiro 	/* Get some VM.  */
    160  1.1  ichiro 	if ((va = uvm_km_valloc(kernel_map, endpa - startpa)) == 0)
    161  1.1  ichiro 		return ENOMEM;
    162  1.1  ichiro 
    163  1.1  ichiro 	/* Store the bus space handle */
    164  1.1  ichiro 	*bshp = va + offset;
    165  1.1  ichiro 
    166  1.1  ichiro 	/* Now map the pages */
    167  1.1  ichiro 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    168  1.2     scw 		pmap_enter(pmap_kernel(), va, pa,
    169  1.2     scw 		    VM_PROT_READ | VM_PROT_WRITE,
    170  1.2     scw 		    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
    171  1.1  ichiro 	}
    172  1.1  ichiro 	pmap_update(pmap_kernel());
    173  1.1  ichiro 
    174  1.1  ichiro 	return(0);
    175  1.1  ichiro }
    176  1.1  ichiro 
    177  1.1  ichiro void
    178  1.1  ichiro ixp425_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
    179  1.1  ichiro {
    180  1.1  ichiro 	vaddr_t	va;
    181  1.1  ichiro 	vaddr_t	endva;
    182  1.1  ichiro 
    183  1.1  ichiro 	if (pmap_devmap_find_va(bsh, size) != NULL) {
    184  1.1  ichiro 		/* Device was statically mapped; nothing to do. */
    185  1.1  ichiro 		return;
    186  1.1  ichiro 	}
    187  1.1  ichiro 
    188  1.1  ichiro 	endva = round_page(bsh + size);
    189  1.1  ichiro 	va = trunc_page(bsh);
    190  1.1  ichiro 
    191  1.1  ichiro 	uvm_km_free(kernel_map, va, endva - va);
    192  1.1  ichiro }
    193  1.1  ichiro 
    194  1.1  ichiro int
    195  1.1  ichiro ixp425_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
    196  1.1  ichiro 	bus_size_t size, bus_size_t alignment, bus_size_t boundary, int cacheable,
    197  1.1  ichiro 	bus_addr_t *bpap, bus_space_handle_t *bshp)
    198  1.1  ichiro {
    199  1.1  ichiro 	panic("ixp425_bs_alloc(): not implemented\n");
    200  1.1  ichiro }
    201  1.1  ichiro 
    202  1.1  ichiro void
    203  1.1  ichiro ixp425_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
    204  1.1  ichiro {
    205  1.1  ichiro 	panic("ixp425_bs_free(): not implemented\n");
    206  1.1  ichiro }
    207  1.1  ichiro 
    208  1.1  ichiro int
    209  1.1  ichiro ixp425_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
    210  1.1  ichiro 	bus_size_t size, bus_space_handle_t *nbshp)
    211  1.1  ichiro {
    212  1.1  ichiro 	*nbshp = bsh + offset;
    213  1.1  ichiro 	return (0);
    214  1.1  ichiro }
    215  1.1  ichiro 
    216  1.1  ichiro void *
    217  1.1  ichiro ixp425_bs_vaddr(void *t, bus_space_handle_t bsh)
    218  1.1  ichiro {
    219  1.1  ichiro 	return ((void *)bsh);
    220  1.1  ichiro }
    221  1.1  ichiro 
    222  1.1  ichiro paddr_t
    223  1.1  ichiro ixp425_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
    224  1.1  ichiro {
    225  1.1  ichiro 	/* Not supported. */
    226  1.1  ichiro 	return (-1);
    227  1.1  ichiro }
    228  1.1  ichiro 
    229  1.1  ichiro void
    230  1.1  ichiro ixp425_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
    231  1.1  ichiro     bus_size_t len, int flags)
    232  1.1  ichiro {
    233  1.1  ichiro /* NULL */
    234  1.1  ichiro }
    235  1.1  ichiro /* End of ixp425_space.c */
    236