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