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