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