Home | History | Annotate | Line # | Download | only in footbridge
footbridge_io.c revision 1.1
      1 /*	$NetBSD: footbridge_io.c,v 1.1 2001/06/09 10:29:12 chris Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Causality Limited
      5  * Copyright (c) 1997 Mark Brinicombe.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by Mark Brinicombe
     19  *	for the NetBSD Project.
     20  * 4. The name of the company nor the name of the author may be used to
     21  *    endorse or promote products derived from this software without specific
     22  *    prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  */
     36 
     37 /*
     38  * bus_space I/O functions for footbridge
     39  */
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <machine/bus.h>
     44 #include <arm/footbridge/dc21285mem.h>
     45 #include <uvm/uvm_extern.h>
     46 
     47 /* Proto types for all the bus_space structure functions */
     48 
     49 bs_protos(footbridge);
     50 bs_protos(bs_notimpl);
     51 bs_map_proto(footbridge_mem);
     52 bs_unmap_proto(footbridge_mem);
     53 
     54 /* Declare the footbridge bus space tag */
     55 
     56 struct bus_space footbridge_bs_tag = {
     57 	/* cookie */
     58 	(void *) 0,			/* Base address */
     59 
     60 	/* mapping/unmapping */
     61 	footbridge_bs_map,
     62 	footbridge_bs_unmap,
     63 	footbridge_bs_subregion,
     64 
     65 	/* allocation/deallocation */
     66 	footbridge_bs_alloc,
     67 	footbridge_bs_free,
     68 
     69 	/* get kernel virtual address */
     70 	footbridge_bs_vaddr,
     71 
     72 	/* barrier */
     73 	footbridge_bs_barrier,
     74 
     75 	/* read (single) */
     76 	footbridge_bs_r_1,
     77 	footbridge_bs_r_2,
     78 	footbridge_bs_r_4,
     79 	bs_notimpl_bs_r_8,
     80 
     81 	/* read multiple */
     82 	footbridge_bs_rm_1,
     83 	footbridge_bs_rm_2,
     84 	footbridge_bs_rm_4,
     85 	bs_notimpl_bs_rm_8,
     86 
     87 	/* read region */
     88 	bs_notimpl_bs_rr_1,
     89 	footbridge_bs_rr_2,
     90 	footbridge_bs_rr_4,
     91 	bs_notimpl_bs_rr_8,
     92 
     93 	/* write (single) */
     94 	footbridge_bs_w_1,
     95 	footbridge_bs_w_2,
     96 	footbridge_bs_w_4,
     97 	bs_notimpl_bs_w_8,
     98 
     99 	/* write multiple */
    100 	footbridge_bs_wm_1,
    101 	footbridge_bs_wm_2,
    102 	footbridge_bs_wm_4,
    103 	bs_notimpl_bs_wm_8,
    104 
    105 	/* write region */
    106 	bs_notimpl_bs_wr_1,
    107 	footbridge_bs_wr_2,
    108 	footbridge_bs_wr_4,
    109 	bs_notimpl_bs_wr_8,
    110 
    111 	/* set multiple */
    112 	bs_notimpl_bs_sm_1,
    113 	bs_notimpl_bs_sm_2,
    114 	bs_notimpl_bs_sm_4,
    115 	bs_notimpl_bs_sm_8,
    116 
    117 	/* set region */
    118 	bs_notimpl_bs_sr_1,
    119 	footbridge_bs_sr_2,
    120 	bs_notimpl_bs_sr_4,
    121 	bs_notimpl_bs_sr_8,
    122 
    123 	/* copy */
    124 	bs_notimpl_bs_c_1,
    125 	footbridge_bs_c_2,
    126 	bs_notimpl_bs_c_4,
    127 	bs_notimpl_bs_c_8,
    128 };
    129 
    130 void footbridge_create_io_bs_tag(t, cookie)
    131 	struct bus_space *t;
    132 	void *cookie;
    133 {
    134 	*t = footbridge_bs_tag;
    135 	t->bs_cookie = cookie;
    136 }
    137 
    138 void footbridge_create_mem_bs_tag(t, cookie)
    139 	struct bus_space *t;
    140 	void *cookie;
    141 {
    142 	*t = footbridge_bs_tag;
    143 	t->bs_map = footbridge_mem_bs_map;
    144 	t->bs_unmap = footbridge_mem_bs_unmap;
    145 	t->bs_cookie = cookie;
    146 }
    147 
    148 /* bus space functions */
    149 
    150 int
    151 footbridge_bs_map(t, bpa, size, cacheable, bshp)
    152 	void *t;
    153 	bus_addr_t bpa;
    154 	bus_size_t size;
    155 	int cacheable;
    156 	bus_space_handle_t *bshp;
    157 {
    158 	/*
    159 	 * The whole 64K of PCI space is always completely mapped during
    160 	 * boot.
    161 	 *
    162 	 * Eventually this function will do the mapping check overlapping /
    163 	 * multiple mappings.
    164 	 */
    165 
    166 	/* The cookie is the base address for the I/O area */
    167 	*bshp = bpa + (bus_addr_t)t;
    168 	return(0);
    169 }
    170 
    171 int
    172 footbridge_mem_bs_map(t, bpa, size, cacheable, bshp)
    173 	void *t;
    174 	bus_addr_t bpa;
    175 	bus_size_t size;
    176 	int cacheable;
    177 	bus_space_handle_t *bshp;
    178 {
    179 	bus_addr_t startpa, endpa;
    180 	vaddr_t va;
    181 
    182 	/* Round the allocation to page boundries */
    183 	startpa = trunc_page(bpa);
    184 	endpa = round_page(bpa + size);
    185 
    186 	/*
    187 	 * Check for mappings below 1MB as we have this space already
    188 	 * mapped. In practice it is only the VGA hole that takes
    189 	 * advantage of this.
    190 	 */
    191 	if (endpa < DC21285_PCI_ISA_MEM_VSIZE) {
    192 		/* Store the bus space handle */
    193 		*bshp = DC21285_PCI_ISA_MEM_VBASE + bpa;
    194 		return 0;
    195 	}
    196 
    197 	/*
    198 	 * Eventually this function will do the mapping check for overlapping /
    199 	 * multiple mappings
    200 	 */
    201 
    202 	va = uvm_km_valloc(kernel_map, endpa - startpa);
    203 	if (va == 0)
    204 		return ENOMEM;
    205 
    206 	/* Store the bus space handle */
    207 	*bshp = va + (bpa & PGOFSET);
    208 
    209 	/* Now map the pages */
    210 	/* The cookie is the physical base address for the I/O area */
    211 	while (startpa < endpa) {
    212 		pmap_enter(kernel_pmap, va, (bus_addr_t)t + startpa,
    213 		    VM_PROT_READ | VM_PROT_WRITE, 0);
    214 		va += NBPG;
    215 		startpa += NBPG;
    216 	}
    217 	pmap_update();
    218 
    219 /*	if (bpa >= DC21285_PCI_MEM_VSIZE && bpa != DC21285_ARMCSR_VBASE)
    220 		panic("footbridge_bs_map: Address out of range (%08lx)\n", bpa);
    221 */
    222 	return(0);
    223 }
    224 
    225 int
    226 footbridge_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
    227     bpap, bshp)
    228 	void *t;
    229 	bus_addr_t rstart, rend;
    230 	bus_size_t size, alignment, boundary;
    231 	int cacheable;
    232 	bus_addr_t *bpap;
    233 	bus_space_handle_t *bshp;
    234 {
    235 	panic("footbridge_alloc(): Help!\n");
    236 }
    237 
    238 
    239 void
    240 footbridge_bs_unmap(t, bsh, size)
    241 	void *t;
    242 	bus_space_handle_t bsh;
    243 	bus_size_t size;
    244 {
    245 	/*
    246 	 * Temporary implementation
    247 	 */
    248 }
    249 
    250 void
    251 footbridge_mem_bs_unmap(t, bsh, size)
    252 	void *t;
    253 	bus_space_handle_t bsh;
    254 	bus_size_t size;
    255 {
    256 	vaddr_t startva, endva;
    257 
    258 	/*
    259 	 * Check for mappings below 1MB as we have this space permenantly
    260 	 * mapped. In practice it is only the VGA hole that takes
    261 	 * advantage of this.
    262 	 */
    263 	if (bsh >= DC21285_PCI_ISA_MEM_VBASE
    264 	    && bsh < (DC21285_PCI_ISA_MEM_VBASE + DC21285_PCI_ISA_MEM_VSIZE)) {
    265 		return;
    266 	}
    267 
    268 	startva = trunc_page(bsh);
    269 	endva = round_page(bsh + size);
    270 
    271 	uvm_km_free(kernel_map, startva, endva - startva);
    272 }
    273 
    274 void
    275 footbridge_bs_free(t, bsh, size)
    276 	void *t;
    277 	bus_space_handle_t bsh;
    278 	bus_size_t size;
    279 {
    280 
    281 	panic("footbridge_free(): Help!\n");
    282 	/* footbridge_bs_unmap() does all that we need to do. */
    283 /*	footbridge_bs_unmap(t, bsh, size);*/
    284 }
    285 
    286 int
    287 footbridge_bs_subregion(t, bsh, offset, size, nbshp)
    288 	void *t;
    289 	bus_space_handle_t bsh;
    290 	bus_size_t offset, size;
    291 	bus_space_handle_t *nbshp;
    292 {
    293 
    294 	*nbshp = bsh + (offset << ((int)t));
    295 	return (0);
    296 }
    297 
    298 void *
    299 footbridge_bs_vaddr(t, bsh)
    300 	void *t;
    301 	bus_space_handle_t bsh;
    302 {
    303 
    304 	return ((void *)bsh);
    305 }
    306 
    307 void
    308 footbridge_bs_barrier(t, bsh, offset, len, flags)
    309 	void *t;
    310 	bus_space_handle_t bsh;
    311 	bus_size_t offset, len;
    312 	int flags;
    313 {
    314 }
    315