Home | History | Annotate | Line # | Download | only in sa11x0
sa11x0_io.c revision 1.12
      1 /*	$NetBSD: sa11x0_io.c,v 1.12 2003/07/15 00:24:51 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Mark Brinicombe.
      5  * Copyright (c) 1997 Causality Limited.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to The NetBSD Foundation
      9  * by Ichiro FUKUHARA.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by Mark Brinicombe.
     22  * 4. The name of the company nor the name of the author may be used to
     23  *    endorse or promote products derived from this software without specific
     24  *    prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     27  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     28  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     29  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     30  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     31  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     32  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * bus_space I/O functions for sa11x0
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: sa11x0_io.c,v 1.12 2003/07/15 00:24:51 lukem Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/queue.h>
     49 
     50 #include <uvm/uvm.h>
     51 
     52 #include <machine/bus.h>
     53 #include <machine/pmap.h>
     54 
     55 /* Proto types for all the bus_space structure functions */
     56 
     57 bs_protos(sa11x0);
     58 bs_protos(bs_notimpl);
     59 
     60 /* Declare the sa11x0 bus space tag */
     61 
     62 struct bus_space sa11x0_bs_tag = {
     63 	/* cookie */
     64 	NULL,
     65 
     66 	/* mapping/unmapping */
     67 	sa11x0_bs_map,
     68 	sa11x0_bs_unmap,
     69 	sa11x0_bs_subregion,
     70 
     71 	/* allocation/deallocation */
     72 	sa11x0_bs_alloc,
     73 	sa11x0_bs_free,
     74 
     75 	/* get kernel virtual address */
     76 	sa11x0_bs_vaddr,
     77 
     78 	/* mmap bus space for userland */
     79 	sa11x0_bs_mmap,
     80 
     81 	/* barrier */
     82 	sa11x0_bs_barrier,
     83 
     84 	/* read (single) */
     85 	sa11x0_bs_r_1,
     86 	sa11x0_bs_r_2,
     87 	sa11x0_bs_r_4,
     88 	bs_notimpl_bs_r_8,
     89 
     90 	/* read multiple */
     91 	sa11x0_bs_rm_1,
     92 	sa11x0_bs_rm_2,
     93 	sa11x0_bs_rm_4,
     94 	bs_notimpl_bs_rm_8,
     95 
     96 	/* read region */
     97 	bs_notimpl_bs_rr_1,
     98 	sa11x0_bs_rr_2,
     99 	bs_notimpl_bs_rr_4,
    100 	bs_notimpl_bs_rr_8,
    101 
    102 	/* write (single) */
    103 	sa11x0_bs_w_1,
    104 	sa11x0_bs_w_2,
    105 	sa11x0_bs_w_4,
    106 	bs_notimpl_bs_w_8,
    107 
    108 	/* write multiple */
    109 	sa11x0_bs_wm_1,
    110 	sa11x0_bs_wm_2,
    111 	sa11x0_bs_wm_4,
    112 	bs_notimpl_bs_wm_8,
    113 
    114 	/* write region */
    115 	bs_notimpl_bs_wr_1,
    116 	sa11x0_bs_wr_2,
    117 	bs_notimpl_bs_wr_4,
    118 	bs_notimpl_bs_wr_8,
    119 
    120 	/* set multiple */
    121 	bs_notimpl_bs_sm_1,
    122 	bs_notimpl_bs_sm_2,
    123 	bs_notimpl_bs_sm_4,
    124 	bs_notimpl_bs_sm_8,
    125 
    126 	/* set region */
    127 	bs_notimpl_bs_sr_1,
    128 	sa11x0_bs_sr_2,
    129 	bs_notimpl_bs_sr_4,
    130 	bs_notimpl_bs_sr_8,
    131 
    132 	/* copy */
    133 	bs_notimpl_bs_c_1,
    134 	sa11x0_bs_c_2,
    135 	bs_notimpl_bs_c_4,
    136 	bs_notimpl_bs_c_8,
    137 };
    138 
    139 /* bus space functions */
    140 
    141 int
    142 sa11x0_bs_map(t, bpa, size, cacheable, bshp)
    143 	void *t;
    144 	bus_addr_t bpa;
    145 	bus_size_t size;
    146 	int cacheable;
    147 	bus_space_handle_t *bshp;
    148 {
    149 	u_long startpa, endpa, pa;
    150 	vaddr_t va;
    151 	pt_entry_t *pte;
    152 
    153 #ifdef hpcarm
    154 	if ((u_long)bpa > (u_long)KERNEL_BASE) {
    155 		/* XXX This is a temporary hack to aid transition. */
    156 		*bshp = bpa;
    157 		return(0);
    158 	}
    159 #endif
    160 
    161 	startpa = trunc_page(bpa);
    162 	endpa = round_page(bpa + size);
    163 
    164 	/* XXX use extent manager to check duplicate mapping */
    165 
    166 	va = uvm_km_valloc(kernel_map, endpa - startpa);
    167 	if (! va)
    168 		return(ENOMEM);
    169 
    170 	*bshp = (bus_space_handle_t)(va + (bpa - startpa));
    171 
    172 	for(pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    173 		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
    174 		pte = vtopte(va);
    175 		if (cacheable == 0) {
    176 			*pte &= ~L2_S_CACHE_MASK;
    177 			PTE_SYNC(pte);
    178 		}
    179 	}
    180 	pmap_update(pmap_kernel());
    181 
    182 	return(0);
    183 }
    184 
    185 int
    186 sa11x0_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
    187     bpap, bshp)
    188 	void *t;
    189 	bus_addr_t rstart, rend;
    190 	bus_size_t size, alignment, boundary;
    191 	int cacheable;
    192 	bus_addr_t *bpap;
    193 	bus_space_handle_t *bshp;
    194 {
    195 	panic("sa11x0_alloc(): Help!");
    196 }
    197 
    198 
    199 void
    200 sa11x0_bs_unmap(t, bsh, size)
    201 	void *t;
    202 	bus_space_handle_t bsh;
    203 	bus_size_t size;
    204 {
    205 	/*
    206 	 * Temporary implementation
    207 	 */
    208 }
    209 
    210 void
    211 sa11x0_bs_free(t, bsh, size)
    212 	void *t;
    213 	bus_space_handle_t bsh;
    214 	bus_size_t size;
    215 {
    216 
    217 	panic("sa11x0_free(): Help!");
    218 	/* sa11x0_unmap() does all that we need to do. */
    219 /*	sa11x0_unmap(t, bsh, size);*/
    220 }
    221 
    222 int
    223 sa11x0_bs_subregion(t, bsh, offset, size, nbshp)
    224 	void *t;
    225 	bus_space_handle_t bsh;
    226 	bus_size_t offset, size;
    227 	bus_space_handle_t *nbshp;
    228 {
    229 
    230 	*nbshp = bsh + offset;
    231 	return (0);
    232 }
    233 
    234 paddr_t
    235 sa11x0_bs_mmap(t, paddr, offset, prot, flags)
    236 	void *t;
    237 	bus_addr_t paddr;
    238 	off_t offset;
    239 	int prot;
    240 	int flags;
    241 {
    242 	/*
    243 	 * mmap from address `paddr+offset' for one page
    244 	 */
    245 	 return (arm_btop((paddr + offset)));
    246 }
    247 
    248 void *
    249 sa11x0_bs_vaddr(t, bsh)
    250 	void *t;
    251 	bus_space_handle_t bsh;
    252 {
    253 	return ((void *)bsh);
    254 }
    255 
    256 void
    257 sa11x0_bs_barrier(t, bsh, offset, len, flags)
    258 	void *t;
    259 	bus_space_handle_t bsh;
    260 	bus_size_t offset, len;
    261 	int flags;
    262 {
    263 /* NULL */
    264 }
    265 
    266 /* End of sa11x0_io.c */
    267