Home | History | Annotate | Line # | Download | only in vr
vrdmaau.c revision 1.6
      1  1.1  takemura /*
      2  1.1  takemura  * Copyright (c) 2001 HAMAJIMA Katsuomi. All rights reserved.
      3  1.1  takemura  *
      4  1.1  takemura  * Redistribution and use in source and binary forms, with or without
      5  1.1  takemura  * modification, are permitted provided that the following conditions
      6  1.1  takemura  * are met:
      7  1.1  takemura  * 1. Redistributions of source code must retain the above copyright
      8  1.1  takemura  *    notice, this list of conditions and the following disclaimer.
      9  1.1  takemura  * 2. Redistributions in binary form must reproduce the above copyright
     10  1.1  takemura  *    notice, this list of conditions and the following disclaimer in the
     11  1.1  takemura  *    documentation and/or other materials provided with the distribution.
     12  1.1  takemura  *
     13  1.1  takemura  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     14  1.1  takemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  1.1  takemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     16  1.1  takemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     17  1.1  takemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     18  1.1  takemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     19  1.1  takemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     20  1.1  takemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     21  1.1  takemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     22  1.1  takemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     23  1.1  takemura  * SUCH DAMAGE.
     24  1.1  takemura  */
     25  1.1  takemura 
     26  1.4     lukem #include <sys/cdefs.h>
     27  1.6       chs __KERNEL_RCSID(0, "$NetBSD: vrdmaau.c,v 1.6 2012/10/27 17:17:56 chs Exp $");
     28  1.4     lukem 
     29  1.1  takemura #include <sys/param.h>
     30  1.1  takemura #include <sys/systm.h>
     31  1.1  takemura #include <sys/device.h>
     32  1.1  takemura 
     33  1.1  takemura #include <machine/bus.h>
     34  1.1  takemura 
     35  1.1  takemura #include <hpcmips/vr/vripif.h>
     36  1.1  takemura #include <hpcmips/vr/dmaaureg.h>
     37  1.1  takemura 
     38  1.1  takemura #ifdef VRDMAAU_DEBUG
     39  1.1  takemura int vrdmaau_debug = VRDMAAU_DEBUG;
     40  1.1  takemura #define DPRINTFN(n,x) if (vrdmaau_debug>(n)) printf x;
     41  1.1  takemura #else
     42  1.1  takemura #define DPRINTFN(n,x)
     43  1.1  takemura #endif
     44  1.1  takemura 
     45  1.1  takemura struct vrdmaau_softc {
     46  1.6       chs 	device_t		sc_dev;
     47  1.1  takemura 	bus_space_tag_t		sc_iot;
     48  1.1  takemura 	bus_space_handle_t	sc_ioh;
     49  1.1  takemura 	struct vrdmaau_chipset_tag	sc_chipset;
     50  1.1  takemura };
     51  1.1  takemura 
     52  1.6       chs int vrdmaau_match(device_t, cfdata_t, void *);
     53  1.6       chs void vrdmaau_attach(device_t, device_t, void *);
     54  1.1  takemura 
     55  1.6       chs CFATTACH_DECL_NEW(vrdmaau, sizeof(struct vrdmaau_softc),
     56  1.3   thorpej     vrdmaau_match, vrdmaau_attach, NULL, NULL);
     57  1.1  takemura 
     58  1.1  takemura int vrdmaau_set_aiuin(vrdmaau_chipset_tag_t, void *);
     59  1.1  takemura int vrdmaau_set_aiuout(vrdmaau_chipset_tag_t, void *);
     60  1.1  takemura int vrdmaau_set_fir(vrdmaau_chipset_tag_t, void *);
     61  1.1  takemura static int vrdmaau_phy_addr(struct vrdmaau_softc *, void *, u_int32_t *);
     62  1.1  takemura 
     63  1.1  takemura int
     64  1.6       chs vrdmaau_match(device_t parent, cfdata_t cf, void *aux)
     65  1.1  takemura {
     66  1.1  takemura 	return 2; /* 1st attach group of vrip */
     67  1.1  takemura }
     68  1.1  takemura 
     69  1.1  takemura void
     70  1.6       chs vrdmaau_attach(device_t parent, device_t self, void *aux)
     71  1.1  takemura {
     72  1.1  takemura 	struct vrip_attach_args *va = aux;
     73  1.6       chs 	struct vrdmaau_softc *sc = device_private(self);
     74  1.1  takemura 
     75  1.6       chs 	sc->sc_dev = self;
     76  1.1  takemura 	sc->sc_iot = va->va_iot;
     77  1.1  takemura 	sc->sc_chipset.ac_sc = sc;
     78  1.1  takemura 	sc->sc_chipset.ac_set_aiuin = vrdmaau_set_aiuin;
     79  1.1  takemura 	sc->sc_chipset.ac_set_aiuout = vrdmaau_set_aiuout;
     80  1.1  takemura 	sc->sc_chipset.ac_set_fir = vrdmaau_set_fir;
     81  1.1  takemura 
     82  1.1  takemura 	if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
     83  1.1  takemura 			  0 /* no flags */, &sc->sc_ioh)) {
     84  1.1  takemura 		printf(": can't map i/o space\n");
     85  1.1  takemura 		return;
     86  1.1  takemura 	}
     87  1.1  takemura 	printf("\n");
     88  1.1  takemura 	vrip_register_dmaau(va->va_vc, &sc->sc_chipset);
     89  1.1  takemura }
     90  1.1  takemura 
     91  1.1  takemura int
     92  1.1  takemura vrdmaau_set_aiuin(vrdmaau_chipset_tag_t ac, void *addr)
     93  1.1  takemura {
     94  1.1  takemura 	struct vrdmaau_softc *sc = ac->ac_sc;
     95  1.1  takemura 	u_int32_t phy;
     96  1.1  takemura 	int err;
     97  1.1  takemura 
     98  1.1  takemura 	DPRINTFN(1, ("vrdmaau_set_aiuin: address %p\n", addr));
     99  1.1  takemura 
    100  1.1  takemura 	if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
    101  1.1  takemura 		return err;
    102  1.1  takemura 
    103  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUIBAH_REG_W, phy >> 16);
    104  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUIBAL_REG_W, phy & 0xffff);
    105  1.1  takemura 	return 0;
    106  1.1  takemura }
    107  1.1  takemura 
    108  1.1  takemura int
    109  1.1  takemura vrdmaau_set_aiuout(vrdmaau_chipset_tag_t ac, void *addr)
    110  1.1  takemura {
    111  1.1  takemura 	struct vrdmaau_softc *sc = ac->ac_sc;
    112  1.1  takemura 	u_int32_t phy;
    113  1.1  takemura 	int err;
    114  1.1  takemura 
    115  1.1  takemura 	DPRINTFN(1, ("vrdmaau_set_aiuout: address %p\n", addr));
    116  1.1  takemura 
    117  1.1  takemura 	if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
    118  1.1  takemura 		return err;
    119  1.1  takemura 
    120  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUOBAH_REG_W, phy >> 16);
    121  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUOBAL_REG_W, phy & 0xffff);
    122  1.1  takemura 	return 0;
    123  1.1  takemura }
    124  1.1  takemura 
    125  1.1  takemura int
    126  1.1  takemura vrdmaau_set_fir(vrdmaau_chipset_tag_t ac, void *addr)
    127  1.1  takemura {
    128  1.1  takemura 	struct vrdmaau_softc *sc = ac->ac_sc;
    129  1.1  takemura 	u_int32_t phy;
    130  1.1  takemura 	int err;
    131  1.1  takemura 
    132  1.1  takemura 	DPRINTFN(1, ("vrdmaau_set_fir: address %p\n", addr));
    133  1.1  takemura 
    134  1.1  takemura 	if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
    135  1.1  takemura 		return err;
    136  1.1  takemura 
    137  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, FIRBAH_REG_W, phy >> 16);
    138  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, FIRBAL_REG_W, phy & 0xffff);
    139  1.1  takemura 	return 0;
    140  1.1  takemura }
    141  1.1  takemura 
    142  1.1  takemura static int
    143  1.1  takemura vrdmaau_phy_addr(struct vrdmaau_softc *sc, void *addr, u_int32_t *phy)
    144  1.1  takemura {
    145  1.1  takemura 	DPRINTFN(1, ("vrdmaau_phy_addr\n"));
    146  1.1  takemura 
    147  1.1  takemura 	if (addr >= (void *)MIPS_KSEG0_START &&
    148  1.1  takemura 	    addr < (void *)MIPS_KSEG1_START)
    149  1.1  takemura 		*phy = MIPS_KSEG0_TO_PHYS(addr);
    150  1.1  takemura 	else if (addr >= (void *)MIPS_KSEG1_START &&
    151  1.1  takemura 		 addr < (void *)MIPS_KSEG2_START)
    152  1.1  takemura 		*phy = MIPS_KSEG1_TO_PHYS(addr);
    153  1.1  takemura 	else {
    154  1.1  takemura 		DPRINTFN(0, ("vrdmaau_map_addr: invalid address %p\n", addr));
    155  1.1  takemura 		return EFAULT;
    156  1.1  takemura 	}
    157  1.1  takemura 
    158  1.1  takemura #ifdef DIAGNOSTIC
    159  1.1  takemura 	if ((*phy & (VRDMAAU_ALIGNMENT - 1)) ||
    160  1.1  takemura 	    *phy >= VRDMAAU_BOUNCE_THRESHOLD ) {
    161  1.1  takemura 		printf("%s: vrdmaau_phy_addr: invalid address %p\n",
    162  1.6       chs 		       device_xname(sc->sc_dev), addr);
    163  1.1  takemura 		return EINVAL;
    164  1.1  takemura 	}
    165  1.1  takemura #endif
    166  1.1  takemura 	return 0;
    167  1.1  takemura }
    168