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