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