Home | History | Annotate | Line # | Download | only in mainbus
mainbus_io.c revision 1.14
      1 /*	$NetBSD: mainbus_io.c,v 1.14 2003/12/06 22:05:33 bjh21 Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Mark Brinicombe.
      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 Mark Brinicombe.
     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 THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     26  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  * 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 /*
     36  * bus_space I/O functions for mainbus
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: mainbus_io.c,v 1.14 2003/12/06 22:05:33 bjh21 Exp $");
     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 #include <machine/pmap.h>
     50 
     51 /* Proto types for all the bus_space structure functions */
     52 
     53 bs_protos(mainbus);
     54 bs_protos(bs_notimpl);
     55 
     56 /* Declare the mainbus bus space tag */
     57 
     58 struct bus_space mainbus_bs_tag = {
     59 	/* cookie */
     60 	NULL,
     61 
     62 	/* mapping/unmapping */
     63 	mainbus_bs_map,
     64 	mainbus_bs_unmap,
     65 	mainbus_bs_subregion,
     66 
     67 	/* allocation/deallocation */
     68 	mainbus_bs_alloc,
     69 	mainbus_bs_free,
     70 
     71 	/* get kernel virtual address */
     72 	0, /* there is no linear mapping */
     73 
     74 	/* Mmap bus space for user */
     75 	mainbus_bs_mmap,
     76 
     77 	/* barrier */
     78 	mainbus_bs_barrier,
     79 
     80 	/* read (single) */
     81 	mainbus_bs_r_1,
     82 	mainbus_bs_r_2,
     83 	mainbus_bs_r_4,
     84 	bs_notimpl_bs_r_8,
     85 
     86 	/* read multiple */
     87 	bs_notimpl_bs_rm_1,
     88 	mainbus_bs_rm_2,
     89 	bs_notimpl_bs_rm_4,
     90 	bs_notimpl_bs_rm_8,
     91 
     92 	/* read region */
     93 	bs_notimpl_bs_rr_1,
     94 	bs_notimpl_bs_rr_2,
     95 	bs_notimpl_bs_rr_4,
     96 	bs_notimpl_bs_rr_8,
     97 
     98 	/* write (single) */
     99 	mainbus_bs_w_1,
    100 	mainbus_bs_w_2,
    101 	mainbus_bs_w_4,
    102 	bs_notimpl_bs_w_8,
    103 
    104 	/* write multiple */
    105 	mainbus_bs_wm_1,
    106 	mainbus_bs_wm_2,
    107 	bs_notimpl_bs_wm_4,
    108 	bs_notimpl_bs_wm_8,
    109 
    110 	/* write region */
    111 	bs_notimpl_bs_wr_1,
    112 	bs_notimpl_bs_wr_2,
    113 	bs_notimpl_bs_wr_4,
    114 	bs_notimpl_bs_wr_8,
    115 
    116 	bs_notimpl_bs_sm_1,
    117 	bs_notimpl_bs_sm_2,
    118 	bs_notimpl_bs_sm_4,
    119 	bs_notimpl_bs_sm_8,
    120 
    121 	/* set region */
    122 	bs_notimpl_bs_sr_1,
    123 	bs_notimpl_bs_sr_2,
    124 	bs_notimpl_bs_sr_4,
    125 	bs_notimpl_bs_sr_8,
    126 
    127 	/* copy */
    128 	bs_notimpl_bs_c_1,
    129 	bs_notimpl_bs_c_2,
    130 	bs_notimpl_bs_c_4,
    131 	bs_notimpl_bs_c_8,
    132 };
    133 
    134 /* bus space functions */
    135 
    136 int
    137 mainbus_bs_map(t, bpa, size, cacheable, bshp)
    138 	void *t;
    139 	bus_addr_t bpa;
    140 	bus_size_t size;
    141 	int cacheable;
    142 	bus_space_handle_t *bshp;
    143 {
    144 	u_long startpa, endpa, pa;
    145 	vaddr_t va;
    146 	pt_entry_t *pte;
    147 
    148 	if ((u_long)bpa > (u_long)KERNEL_BASE) {
    149 		/* XXX This is a temporary hack to aid transition. */
    150 		*bshp = bpa;
    151 		return(0);
    152 	}
    153 
    154 	startpa = trunc_page(bpa);
    155 	endpa = round_page(bpa + size);
    156 
    157 	/* XXX use extent manager to check duplicate mapping */
    158 
    159 	va = uvm_km_valloc(kernel_map, endpa - startpa);
    160 	if (! va)
    161 		return(ENOMEM);
    162 
    163 	*bshp = (bus_space_handle_t)(va + (bpa - startpa));
    164 
    165 	for(pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
    166 		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
    167 		pte = vtopte(va);
    168 		if (cacheable == 0) {
    169 			*pte &= ~L2_S_CACHE_MASK;
    170 			PTE_SYNC(pte);
    171 		}
    172 	}
    173 	pmap_update(pmap_kernel());
    174 
    175 	return(0);
    176 }
    177 
    178 int
    179 mainbus_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
    180     bpap, bshp)
    181 	void *t;
    182 	bus_addr_t rstart, rend;
    183 	bus_size_t size, alignment, boundary;
    184 	int cacheable;
    185 	bus_addr_t *bpap;
    186 	bus_space_handle_t *bshp;
    187 {
    188 	panic("mainbus_bs_alloc(): Help!");
    189 }
    190 
    191 
    192 void
    193 mainbus_bs_unmap(t, bsh, size)
    194 	void *t;
    195 	bus_space_handle_t bsh;
    196 	bus_size_t size;
    197 {
    198 	/*
    199 	 * Temporary implementation
    200 	 */
    201 }
    202 
    203 void
    204 mainbus_bs_free(t, bsh, size)
    205 	void *t;
    206 	bus_space_handle_t bsh;
    207 	bus_size_t size;
    208 {
    209 
    210 	panic("mainbus_bs_free(): Help!");
    211 	/* mainbus_bs_unmap() does all that we need to do. */
    212 /*	mainbus_bs_unmap(t, bsh, size);*/
    213 }
    214 
    215 int
    216 mainbus_bs_subregion(t, bsh, offset, size, nbshp)
    217 	void *t;
    218 	bus_space_handle_t bsh;
    219 	bus_size_t offset, size;
    220 	bus_space_handle_t *nbshp;
    221 {
    222 
    223 	*nbshp = bsh + (offset << 2);
    224 	return (0);
    225 }
    226 
    227 paddr_t
    228 mainbus_bs_mmap(t, paddr, offset, prot, flags)
    229 	void *t;
    230 	bus_addr_t paddr;
    231 	off_t offset;
    232 	int prot;
    233 	int flags;
    234 {
    235 	/*
    236 	 * mmap from address `paddr+offset' for one page
    237 	 */
    238 	 return (arm_btop((paddr + offset)));
    239 }
    240 
    241 void
    242 mainbus_bs_barrier(t, bsh, offset, len, flags)
    243 	void *t;
    244 	bus_space_handle_t bsh;
    245 	bus_size_t offset, len;
    246 	int flags;
    247 {
    248 }
    249 
    250 /* End of mainbus_io.c */
    251