Home | History | Annotate | Line # | Download | only in vr
      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.7      matt __KERNEL_RCSID(0, "$NetBSD: vrdmaau.c,v 1.7 2015/06/09 22:46:36 matt Exp $");
     28  1.4     lukem 
     29  1.1  takemura #include <sys/param.h>
     30  1.7      matt #include <sys/bus.h>
     31  1.7      matt #include <sys/device.h>
     32  1.1  takemura #include <sys/systm.h>
     33  1.1  takemura 
     34  1.7      matt #include <mips/cpuregs.h>
     35  1.1  takemura 
     36  1.1  takemura #include <hpcmips/vr/vripif.h>
     37  1.1  takemura #include <hpcmips/vr/dmaaureg.h>
     38  1.1  takemura 
     39  1.1  takemura #ifdef VRDMAAU_DEBUG
     40  1.1  takemura int vrdmaau_debug = VRDMAAU_DEBUG;
     41  1.1  takemura #define DPRINTFN(n,x) if (vrdmaau_debug>(n)) printf x;
     42  1.1  takemura #else
     43  1.1  takemura #define DPRINTFN(n,x)
     44  1.1  takemura #endif
     45  1.1  takemura 
     46  1.1  takemura struct vrdmaau_softc {
     47  1.6       chs 	device_t		sc_dev;
     48  1.1  takemura 	bus_space_tag_t		sc_iot;
     49  1.1  takemura 	bus_space_handle_t	sc_ioh;
     50  1.1  takemura 	struct vrdmaau_chipset_tag	sc_chipset;
     51  1.1  takemura };
     52  1.1  takemura 
     53  1.6       chs int vrdmaau_match(device_t, cfdata_t, void *);
     54  1.6       chs void vrdmaau_attach(device_t, device_t, void *);
     55  1.1  takemura 
     56  1.6       chs CFATTACH_DECL_NEW(vrdmaau, sizeof(struct vrdmaau_softc),
     57  1.3   thorpej     vrdmaau_match, vrdmaau_attach, NULL, NULL);
     58  1.1  takemura 
     59  1.1  takemura int vrdmaau_set_aiuin(vrdmaau_chipset_tag_t, void *);
     60  1.1  takemura int vrdmaau_set_aiuout(vrdmaau_chipset_tag_t, void *);
     61  1.1  takemura int vrdmaau_set_fir(vrdmaau_chipset_tag_t, void *);
     62  1.1  takemura static int vrdmaau_phy_addr(struct vrdmaau_softc *, void *, u_int32_t *);
     63  1.1  takemura 
     64  1.1  takemura int
     65  1.6       chs vrdmaau_match(device_t parent, cfdata_t cf, void *aux)
     66  1.1  takemura {
     67  1.1  takemura 	return 2; /* 1st attach group of vrip */
     68  1.1  takemura }
     69  1.1  takemura 
     70  1.1  takemura void
     71  1.6       chs vrdmaau_attach(device_t parent, device_t self, void *aux)
     72  1.1  takemura {
     73  1.1  takemura 	struct vrip_attach_args *va = aux;
     74  1.6       chs 	struct vrdmaau_softc *sc = device_private(self);
     75  1.1  takemura 
     76  1.6       chs 	sc->sc_dev = self;
     77  1.1  takemura 	sc->sc_iot = va->va_iot;
     78  1.1  takemura 	sc->sc_chipset.ac_sc = sc;
     79  1.1  takemura 	sc->sc_chipset.ac_set_aiuin = vrdmaau_set_aiuin;
     80  1.1  takemura 	sc->sc_chipset.ac_set_aiuout = vrdmaau_set_aiuout;
     81  1.1  takemura 	sc->sc_chipset.ac_set_fir = vrdmaau_set_fir;
     82  1.1  takemura 
     83  1.1  takemura 	if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
     84  1.1  takemura 			  0 /* no flags */, &sc->sc_ioh)) {
     85  1.1  takemura 		printf(": can't map i/o space\n");
     86  1.1  takemura 		return;
     87  1.1  takemura 	}
     88  1.1  takemura 	printf("\n");
     89  1.1  takemura 	vrip_register_dmaau(va->va_vc, &sc->sc_chipset);
     90  1.1  takemura }
     91  1.1  takemura 
     92  1.1  takemura int
     93  1.1  takemura vrdmaau_set_aiuin(vrdmaau_chipset_tag_t ac, void *addr)
     94  1.1  takemura {
     95  1.1  takemura 	struct vrdmaau_softc *sc = ac->ac_sc;
     96  1.1  takemura 	u_int32_t phy;
     97  1.1  takemura 	int err;
     98  1.1  takemura 
     99  1.1  takemura 	DPRINTFN(1, ("vrdmaau_set_aiuin: address %p\n", addr));
    100  1.1  takemura 
    101  1.1  takemura 	if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
    102  1.1  takemura 		return err;
    103  1.1  takemura 
    104  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUIBAH_REG_W, phy >> 16);
    105  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUIBAL_REG_W, phy & 0xffff);
    106  1.1  takemura 	return 0;
    107  1.1  takemura }
    108  1.1  takemura 
    109  1.1  takemura int
    110  1.1  takemura vrdmaau_set_aiuout(vrdmaau_chipset_tag_t ac, void *addr)
    111  1.1  takemura {
    112  1.1  takemura 	struct vrdmaau_softc *sc = ac->ac_sc;
    113  1.1  takemura 	u_int32_t phy;
    114  1.1  takemura 	int err;
    115  1.1  takemura 
    116  1.1  takemura 	DPRINTFN(1, ("vrdmaau_set_aiuout: address %p\n", addr));
    117  1.1  takemura 
    118  1.1  takemura 	if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
    119  1.1  takemura 		return err;
    120  1.1  takemura 
    121  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUOBAH_REG_W, phy >> 16);
    122  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUOBAL_REG_W, phy & 0xffff);
    123  1.1  takemura 	return 0;
    124  1.1  takemura }
    125  1.1  takemura 
    126  1.1  takemura int
    127  1.1  takemura vrdmaau_set_fir(vrdmaau_chipset_tag_t ac, void *addr)
    128  1.1  takemura {
    129  1.1  takemura 	struct vrdmaau_softc *sc = ac->ac_sc;
    130  1.1  takemura 	u_int32_t phy;
    131  1.1  takemura 	int err;
    132  1.1  takemura 
    133  1.1  takemura 	DPRINTFN(1, ("vrdmaau_set_fir: address %p\n", addr));
    134  1.1  takemura 
    135  1.1  takemura 	if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
    136  1.1  takemura 		return err;
    137  1.1  takemura 
    138  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, FIRBAH_REG_W, phy >> 16);
    139  1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, FIRBAL_REG_W, phy & 0xffff);
    140  1.1  takemura 	return 0;
    141  1.1  takemura }
    142  1.1  takemura 
    143  1.1  takemura static int
    144  1.1  takemura vrdmaau_phy_addr(struct vrdmaau_softc *sc, void *addr, u_int32_t *phy)
    145  1.1  takemura {
    146  1.1  takemura 	DPRINTFN(1, ("vrdmaau_phy_addr\n"));
    147  1.1  takemura 
    148  1.1  takemura 	if (addr >= (void *)MIPS_KSEG0_START &&
    149  1.1  takemura 	    addr < (void *)MIPS_KSEG1_START)
    150  1.1  takemura 		*phy = MIPS_KSEG0_TO_PHYS(addr);
    151  1.1  takemura 	else if (addr >= (void *)MIPS_KSEG1_START &&
    152  1.1  takemura 		 addr < (void *)MIPS_KSEG2_START)
    153  1.1  takemura 		*phy = MIPS_KSEG1_TO_PHYS(addr);
    154  1.1  takemura 	else {
    155  1.1  takemura 		DPRINTFN(0, ("vrdmaau_map_addr: invalid address %p\n", addr));
    156  1.1  takemura 		return EFAULT;
    157  1.1  takemura 	}
    158  1.1  takemura 
    159  1.1  takemura #ifdef DIAGNOSTIC
    160  1.1  takemura 	if ((*phy & (VRDMAAU_ALIGNMENT - 1)) ||
    161  1.1  takemura 	    *phy >= VRDMAAU_BOUNCE_THRESHOLD ) {
    162  1.1  takemura 		printf("%s: vrdmaau_phy_addr: invalid address %p\n",
    163  1.6       chs 		       device_xname(sc->sc_dev), addr);
    164  1.1  takemura 		return EINVAL;
    165  1.1  takemura 	}
    166  1.1  takemura #endif
    167  1.1  takemura 	return 0;
    168  1.1  takemura }
    169