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