Home | History | Annotate | Line # | Download | only in vsa
tc_vsbus.c revision 1.5
      1  1.5  matt /*	$NetBSD: tc_vsbus.c,v 1.5 2010/12/14 23:31:17 matt Exp $	*/
      2  1.1  matt /*-
      3  1.1  matt  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      4  1.1  matt  * All rights reserved.
      5  1.1  matt  *
      6  1.1  matt  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1  matt  * by Matt Thomas <matt (at) 3am-software.com>.
      8  1.1  matt  *
      9  1.1  matt  * Redistribution and use in source and binary forms, with or without
     10  1.1  matt  * modification, are permitted provided that the following conditions
     11  1.1  matt  * are met:
     12  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     13  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     14  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  matt  *    documentation and/or other materials provided with the distribution.
     17  1.1  matt  *
     18  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.1  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.1  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.1  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.1  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.1  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.1  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.1  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.1  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.1  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.1  matt  * POSSIBILITY OF SUCH DAMAGE.
     29  1.1  matt  */
     30  1.1  matt 
     31  1.1  matt #include <sys/param.h>
     32  1.5  matt #include <sys/bus.h>
     33  1.5  matt #include <sys/cpu.h>
     34  1.1  matt #include <sys/device.h>
     35  1.1  matt 
     36  1.1  matt #include <machine/pte.h>
     37  1.1  matt #include <machine/scb.h>
     38  1.1  matt #include <machine/vsbus.h>
     39  1.1  matt #include <dev/tc/tcvar.h>
     40  1.1  matt 
     41  1.2  matt static int tcbus_match(device_t, cfdata_t, void *);
     42  1.2  matt static void tcbus_attach(device_t, device_t, void *);
     43  1.1  matt 
     44  1.1  matt struct tcbus_softc {
     45  1.1  matt 	struct tc_softc sc_tc;
     46  1.1  matt 	struct tc_slotdesc sc_slots[1];
     47  1.1  matt 	struct vax_bus_dma_tag sc_dmatag;
     48  1.1  matt 	struct vax_sgmap sc_sgmap;
     49  1.1  matt 	struct evcnt sc_ev;
     50  1.1  matt 	bus_space_handle_t sc_memh;
     51  1.1  matt };
     52  1.1  matt 
     53  1.1  matt static bus_dma_tag_t tcbus_dmat;
     54  1.1  matt 
     55  1.1  matt CFATTACH_DECL(tcbus, sizeof(struct tcbus_softc),
     56  1.1  matt     tcbus_match, tcbus_attach, 0, 0);
     57  1.1  matt 
     58  1.1  matt static bus_dma_tag_t
     59  1.1  matt tcbus_get_dma_tag(int slotno)
     60  1.1  matt {
     61  1.1  matt 	return tcbus_dmat;
     62  1.1  matt }
     63  1.1  matt 
     64  1.1  matt static void
     65  1.2  matt tcbus_intr_establish(device_t dv, void *cookie, int level,
     66  1.1  matt 	int (*func)(void *), void *arg)
     67  1.1  matt {
     68  1.1  matt 	struct tcbus_softc * const sc = cookie;
     69  1.1  matt 
     70  1.1  matt 	scb_vecalloc(0x51, (void (*)(void *)) func, arg, SCB_ISTACK,
     71  1.1  matt 	    &sc->sc_ev);
     72  1.1  matt }
     73  1.1  matt 
     74  1.1  matt static void
     75  1.2  matt tcbus_intr_disestablish(device_t dv, void *cookie)
     76  1.1  matt {
     77  1.1  matt }
     78  1.1  matt 
     79  1.1  matt static const struct evcnt *
     80  1.2  matt tcbus_intr_evcnt(device_t dv, void *cookie)
     81  1.1  matt {
     82  1.1  matt 	return NULL;
     83  1.1  matt }
     84  1.1  matt 
     85  1.1  matt int
     86  1.2  matt tcbus_match(device_t parent, cfdata_t cfdata, void *aux)
     87  1.1  matt {
     88  1.1  matt 	return 0;
     89  1.1  matt }
     90  1.1  matt 
     91  1.1  matt #define	KA4x_TURBO	0x30000000
     92  1.1  matt #define	KA4x_TURBOMAPS	0x35800000
     93  1.1  matt #define	KA4x_TURBOCSR	0x36800000
     94  1.1  matt 
     95  1.1  matt void
     96  1.2  matt tcbus_attach(device_t parent, device_t self, void *aux)
     97  1.1  matt {
     98  1.1  matt 	struct vsbus_attach_args * const va = aux;
     99  1.3  matt 	struct tcbus_softc * const sc = device_private(self);
    100  1.1  matt 	struct tcbus_attach_args tba;
    101  1.1  matt 	struct pte *pte;
    102  1.1  matt 	const size_t nentries = 32768;
    103  1.1  matt 	int error;
    104  1.1  matt 	int i;
    105  1.1  matt 
    106  1.1  matt 	error = bus_space_map(va->va_memt, KA4x_TURBO, 0x10000,
    107  1.1  matt 	    BUS_SPACE_MAP_LINEAR, &sc->sc_memh);
    108  1.1  matt 	if (error) {
    109  1.1  matt 		aprint_error(": failed to map TC slot 0: %d\n", error);
    110  1.1  matt 		return;
    111  1.1  matt 	}
    112  1.1  matt 
    113  1.1  matt 	sc->sc_slots[0].tcs_addr = sc->sc_memh;
    114  1.1  matt 	sc->sc_slots[0].tcs_cookie = sc;
    115  1.1  matt 
    116  1.1  matt 	tba.tba_speed = TC_SPEED_12_5_MHZ;
    117  1.1  matt 	tba.tba_slots = sc->sc_slots;
    118  1.1  matt 	tba.tba_nslots = 1;
    119  1.1  matt 	tba.tba_intr_evcnt = tcbus_intr_evcnt;
    120  1.1  matt 	tba.tba_intr_establish = tcbus_intr_establish;
    121  1.1  matt 	tba.tba_intr_disestablish = tcbus_intr_disestablish;
    122  1.1  matt 	tba.tba_get_dma_tag = tcbus_get_dma_tag;
    123  1.1  matt 
    124  1.1  matt 	vax_sgmap_dmatag_init(&sc->sc_dmatag, sc, nentries);
    125  1.1  matt 	pte = (struct pte *) vax_map_physmem(KA4x_TURBOMAPS,
    126  1.1  matt 	    nentries * sizeof(pte[0]));
    127  1.1  matt 
    128  1.1  matt 	for (i = nentries; i > 0; )
    129  1.1  matt 		((uint32_t *) pte)[--i] = 0;
    130  1.1  matt 
    131  1.1  matt 	sc->sc_dmatag._sgmap = &sc->sc_sgmap;
    132  1.1  matt 	/*
    133  1.1  matt 	 * Initialize the SGMAP.
    134  1.1  matt 	 */
    135  1.1  matt 	vax_sgmap_init(&sc->sc_dmatag, &sc->sc_sgmap, "tc_sgmap",
    136  1.1  matt 	     sc->sc_dmatag._wbase, sc->sc_dmatag._wsize, pte, 0);
    137  1.1  matt 
    138  1.1  matt 	aprint_normal("\n");
    139  1.1  matt 
    140  1.2  matt 	aprint_verbose_dev(self, "32K entry DMA SGMAP at PA 0x%x (VA %p)\n",
    141  1.2  matt 	     KA4x_TURBOMAPS, pte);
    142  1.1  matt 
    143  1.1  matt 	tcbus_dmat = &sc->sc_dmatag;
    144  1.1  matt 
    145  1.1  matt 	tcattach(parent, self, &tba);
    146  1.1  matt }
    147