Home | History | Annotate | Line # | Download | only in sun3x
vme.c revision 1.12.8.1
      1  1.12.8.1        ad /*	$NetBSD: vme.c,v 1.12.8.1 2007/02/09 21:03:50 ad Exp $	*/
      2       1.1       gwr 
      3       1.1       gwr /*-
      4       1.1       gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5       1.1       gwr  * All rights reserved.
      6       1.1       gwr  *
      7       1.1       gwr  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1       gwr  * by Gordon W. Ross.
      9       1.1       gwr  *
     10       1.1       gwr  * Redistribution and use in source and binary forms, with or without
     11       1.1       gwr  * modification, are permitted provided that the following conditions
     12       1.1       gwr  * are met:
     13       1.1       gwr  * 1. Redistributions of source code must retain the above copyright
     14       1.1       gwr  *    notice, this list of conditions and the following disclaimer.
     15       1.1       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1       gwr  *    notice, this list of conditions and the following disclaimer in the
     17       1.1       gwr  *    documentation and/or other materials provided with the distribution.
     18       1.1       gwr  * 3. All advertising materials mentioning features or use of this software
     19       1.1       gwr  *    must display the following acknowledgement:
     20       1.1       gwr  *        This product includes software developed by the NetBSD
     21       1.1       gwr  *        Foundation, Inc. and its contributors.
     22       1.1       gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1       gwr  *    contributors may be used to endorse or promote products derived
     24       1.1       gwr  *    from this software without specific prior written permission.
     25       1.1       gwr  *
     26       1.1       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1       gwr  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1       gwr  */
     38       1.8     lukem 
     39       1.8     lukem #include <sys/cdefs.h>
     40  1.12.8.1        ad __KERNEL_RCSID(0, "$NetBSD: vme.c,v 1.12.8.1 2007/02/09 21:03:50 ad Exp $");
     41       1.1       gwr 
     42       1.1       gwr #include <sys/param.h>
     43       1.1       gwr #include <sys/systm.h>
     44       1.1       gwr #include <sys/device.h>
     45       1.1       gwr 
     46  1.12.8.1        ad #include <uvm/uvm_extern.h>
     47  1.12.8.1        ad 
     48  1.12.8.1        ad #define _SUN68K_BUS_DMA_PRIVATE
     49       1.1       gwr #include <machine/autoconf.h>
     50  1.12.8.1        ad #include <machine/bus.h>
     51  1.12.8.1        ad #include <machine/dvma.h>
     52  1.12.8.1        ad #include <machine/pmap.h>
     53  1.12.8.1        ad 
     54  1.12.8.1        ad #include <sun3/sun3x/vme.h>
     55       1.1       gwr 
     56       1.2       gwr /* Does this machine have a VME bus? */
     57       1.2       gwr extern int cpu_has_vme;
     58       1.1       gwr 
     59       1.4       gwr /*
     60       1.4       gwr  * Convert vme unit number to bus type,
     61       1.4       gwr  * but only for supported bus types.
     62       1.4       gwr  * (See autoconf.h and vme.h)
     63       1.4       gwr  */
     64       1.4       gwr #define VME_UNITS	6
     65       1.4       gwr static const struct {
     66       1.4       gwr 	int bustype;
     67  1.12.8.1        ad 	const char *name;
     68  1.12.8.1        ad 	int pmtype;
     69  1.12.8.1        ad 	vaddr_t base;
     70  1.12.8.1        ad 	vaddr_t mask;
     71       1.4       gwr } vme_info[VME_UNITS] = {
     72  1.12.8.1        ad 	{ BUS_VME16D16, "A16/D16", PMAP_VME16, VME16_BASE, VME16_MASK },
     73  1.12.8.1        ad 	{ BUS_VME16D32, "A16/D32", PMAP_VME32, VME16_BASE, VME16_MASK },
     74  1.12.8.1        ad 	{ BUS_VME24D16, "A24/D16", PMAP_VME16, VME24_BASE, VME24_MASK },
     75  1.12.8.1        ad 	{ BUS_VME24D32, "A24/D32", PMAP_VME32, VME24_BASE, VME24_MASK },
     76  1.12.8.1        ad 	{ BUS_VME32D16, "A32/D16", PMAP_VME16, VME32_BASE, VME32_MASK },
     77  1.12.8.1        ad 	{ BUS_VME32D32, "A32/D32", PMAP_VME32, VME32_BASE, VME32_MASK },
     78       1.4       gwr };
     79       1.4       gwr 
     80       1.9       chs static int  vme_match(struct device *, struct cfdata *, void *);
     81       1.9       chs static void vme_attach(struct device *, struct device *, void *);
     82       1.1       gwr 
     83  1.12.8.1        ad struct vme_softc {
     84  1.12.8.1        ad 	struct device	sc_dev;
     85  1.12.8.1        ad 	bus_space_tag_t	sc_bustag;
     86  1.12.8.1        ad 	bus_dma_tag_t	sc_dmatag;
     87  1.12.8.1        ad 	int		sc_bustype;
     88  1.12.8.1        ad };
     89  1.12.8.1        ad 
     90  1.12.8.1        ad CFATTACH_DECL(vme, sizeof(struct vme_softc),
     91       1.7   thorpej     vme_match, vme_attach, NULL, NULL);
     92       1.1       gwr 
     93  1.12.8.1        ad static int vme_bus_map(bus_space_tag_t, bus_type_t, bus_addr_t, bus_size_t,
     94  1.12.8.1        ad     int, vaddr_t, bus_space_handle_t *);
     95  1.12.8.1        ad static paddr_t vme_bus_mmap(bus_space_tag_t, bus_type_t, bus_addr_t,
     96  1.12.8.1        ad     off_t, int, int);
     97  1.12.8.1        ad static int vme_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
     98  1.12.8.1        ad     struct proc *, int);
     99  1.12.8.1        ad 
    100  1.12.8.1        ad static struct sun68k_bus_space_tag vme_space_tag = {
    101  1.12.8.1        ad 	NULL,				/* cookie */
    102  1.12.8.1        ad 	NULL,				/* parent bus space tag */
    103  1.12.8.1        ad 	vme_bus_map,			/* bus_space_map */
    104  1.12.8.1        ad 	NULL,				/* bus_space_unmap */
    105  1.12.8.1        ad 	NULL,				/* bus_space_subregion */
    106  1.12.8.1        ad 	NULL,				/* bus_space_barrier */
    107  1.12.8.1        ad 	vme_bus_mmap,			/* bus_space_mmap */
    108  1.12.8.1        ad 	NULL,				/* bus_intr_establish */
    109  1.12.8.1        ad 	NULL,				/* bus_space_peek_N */
    110  1.12.8.1        ad 	NULL				/* bus_space_poke_N */
    111  1.12.8.1        ad };
    112  1.12.8.1        ad 
    113  1.12.8.1        ad static struct sun68k_bus_dma_tag vme_dma_tag;
    114  1.12.8.1        ad 
    115       1.9       chs static int
    116       1.9       chs vme_match(struct device *parent, struct cfdata *cf, void *aux)
    117       1.1       gwr {
    118       1.1       gwr 	struct confargs *ca = aux;
    119       1.4       gwr 	int unit;
    120       1.1       gwr 
    121       1.2       gwr 	if (cpu_has_vme == 0)
    122       1.1       gwr 		return (0);
    123       1.1       gwr 
    124       1.2       gwr 	unit = cf->cf_unit;
    125       1.2       gwr 	if (unit >= VME_UNITS)
    126       1.2       gwr 		return (0);
    127       1.4       gwr 
    128       1.4       gwr 	if (ca->ca_bustype != vme_info[unit].bustype)
    129       1.2       gwr 		return (0);
    130       1.1       gwr 
    131       1.2       gwr 	return (1);
    132       1.1       gwr }
    133       1.1       gwr 
    134       1.9       chs static void
    135       1.9       chs vme_attach(struct device *parent, struct device *self, void *args)
    136       1.1       gwr {
    137  1.12.8.1        ad 	struct confargs *ca = aux;
    138  1.12.8.1        ad 	struct vme_softc *sc = (void *)self;
    139  1.12.8.1        ad 	struct confargs vmea;
    140       1.4       gwr 	int unit;
    141       1.2       gwr 
    142      1.12   thorpej 	unit = device_unit(self);
    143       1.4       gwr 	printf(": (%s)\n", vme_info[unit].name);
    144       1.1       gwr 
    145  1.12.8.1        ad 	sc->sc_bustag = ca->ca_bustag;
    146  1.12.8.1        ad 	sc->sc_dmatag = ca->ca_dmatag;
    147  1.12.8.1        ad 	sc->sc_bustype = unit;
    148  1.12.8.1        ad 
    149  1.12.8.1        ad 	vme_space_tag.cookie = sc;
    150  1.12.8.1        ad 	vme_space_tag.parent = sc->sc_bustag;
    151  1.12.8.1        ad 
    152  1.12.8.1        ad 	vme_dma_tag = *sc->sc_dmatag;
    153  1.12.8.1        ad 	vme_dma_tag._cookie = sc;
    154  1.12.8.1        ad 	vme_dma_tag._dmamap_load = vme_dmamap_load;
    155  1.12.8.1        ad 
    156  1.12.8.1        ad 	vmea = *ca;
    157  1.12.8.1        ad 	vmea.ca_bustag = &vme_space_tag;
    158  1.12.8.1        ad 	vmea.ca_dmatag = &vme_dma_tag;
    159  1.12.8.1        ad 
    160       1.1       gwr 	/* We know ca_bustype == BUS_VMExx */
    161      1.10  drochner 	config_search_ia(bus_scan, self, "vme", args);
    162       1.1       gwr }
    163  1.12.8.1        ad 
    164  1.12.8.1        ad int
    165  1.12.8.1        ad vme_bus_map(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr,
    166  1.12.8.1        ad     bus_size_t size, int flags, vaddr_t vaddr, bus_space_handle_t *hp)
    167  1.12.8.1        ad {
    168  1.12.8.1        ad 	struct vme_softc *sc = t->cookie;
    169  1.12.8.1        ad 	paddr_t pa;
    170  1.12.8.1        ad 	int bustype, pmtype;
    171  1.12.8.1        ad 
    172  1.12.8.1        ad 	bustype = sc->sc_bustype;
    173  1.12.8.1        ad 	pa = paddr;
    174  1.12.8.1        ad 	pa &= vme_info[bustype].mask;
    175  1.12.8.1        ad 	pa |= vme_info[bustype].base;
    176  1.12.8.1        ad 	pmtype = vme_info[bustype].pmtype;
    177  1.12.8.1        ad 
    178  1.12.8.1        ad 	return bus_space_map2(sc->sc_bustag, pmtype, pa, size,
    179  1.12.8.1        ad 	    flags | _SUN68K_BUS_MAP_USE_PROM, vaddr, hp);
    180  1.12.8.1        ad }
    181  1.12.8.1        ad 
    182  1.12.8.1        ad paddr_t
    183  1.12.8.1        ad vme_bus_mmap(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, off_t off,
    184  1.12.8.1        ad     int prot, int flags)
    185  1.12.8.1        ad {
    186  1.12.8.1        ad 	struct vme_softc *sc = t->cookie;
    187  1.12.8.1        ad 	paddr_t pa;
    188  1.12.8.1        ad 	int bustype, pmtype;
    189  1.12.8.1        ad 
    190  1.12.8.1        ad 	bustype = sc->sc_bustype;
    191  1.12.8.1        ad 	pa = paddr;
    192  1.12.8.1        ad 	pa &= vme_info[bustype].mask;
    193  1.12.8.1        ad 	pa |= vme_info[bustype].base;
    194  1.12.8.1        ad 	pmtype = vme_info[bustype].pmtype;
    195  1.12.8.1        ad 
    196  1.12.8.1        ad 	return bus_space_mmap2(sc->sc_bustag, pmtype, pa, off, prot, flags);
    197  1.12.8.1        ad }
    198  1.12.8.1        ad 
    199  1.12.8.1        ad static int
    200  1.12.8.1        ad vme_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
    201  1.12.8.1        ad     bus_size_t buflen, struct proc *p, int flags)
    202  1.12.8.1        ad {
    203  1.12.8.1        ad 	int error;
    204  1.12.8.1        ad 
    205  1.12.8.1        ad 	error = _bus_dmamap_load(t, map, buf, buflen, p, flags);
    206  1.12.8.1        ad 	if (error == 0)
    207  1.12.8.1        ad 		map->dm_segs[0].ds_addr &= DVMA_VME_SLAVE_MASK;
    208  1.12.8.1        ad 	return error;
    209  1.12.8.1        ad }
    210