pcctwo.c revision 1.3 1 /* $NetBSD: pcctwo.c,v 1.3 2003/07/14 15:47:20 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * PCCchip2 and MCchip Driver
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: pcctwo.c,v 1.3 2003/07/14 15:47:20 lukem Exp $");
45
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50
51 #include <machine/cpu.h>
52 #include <machine/bus.h>
53
54 #include <dev/mvme/pcctworeg.h>
55 #include <dev/mvme/pcctwovar.h>
56
57 /*
58 * Global Pointer to the PCCChip2/MCchip soft state, and chip ID
59 */
60 struct pcctwo_softc *sys_pcctwo;
61
62 int pcctwoprint(void *, const char *);
63
64
65 /* ARGSUSED */
66 void
67 pcctwo_init(sc, pd, devoff)
68 struct pcctwo_softc *sc;
69 struct pcctwo_device *pd;
70 int devoff;
71 {
72 struct pcctwo_attach_args npa;
73 u_int8_t cid;
74
75 /*
76 * Fix up the vector base for PCCChip2 Interrupts
77 */
78 pcc2_reg_write(sc, PCC2REG_VECTOR_BASE, sc->sc_vecbase);
79
80 /*
81 * Enable PCCChip2 Interrupts
82 */
83 pcc2_reg_write(sc, PCC2REG_GENERAL_CONTROL,
84 pcc2_reg_read(sc, PCC2REG_GENERAL_CONTROL) | PCCTWO_GEN_CTRL_MIEN);
85
86 /* What are we? */
87 cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID);
88
89 /*
90 * Announce ourselves to the world in general
91 */
92 if (cid == PCCTWO_CHIP_ID_PCC2)
93 printf(": Peripheral Channel Controller (PCCchip2), Rev %d\n",
94 pcc2_reg_read(sc, PCC2REG_CHIP_REVISION));
95 else
96 if (cid == PCCTWO_CHIP_ID_MCCHIP)
97 printf(": Memory Controller ASIC (MCchip), Rev %d\n",
98 pcc2_reg_read(sc, PCC2REG_CHIP_REVISION));
99
100 /*
101 * Attach configured children.
102 */
103 npa._pa_base = devoff;
104 while (pd->pcc_name != NULL) {
105 /*
106 * Note that IPL is filled in by match function.
107 */
108 npa.pa_name = pd->pcc_name;
109 npa.pa_ipl = -1;
110 npa.pa_dmat = sc->sc_dmat;
111 npa.pa_bust = sc->sc_bust;
112 npa.pa_offset = pd->pcc_offset + devoff;
113 pd++;
114
115 /* Attach the device if configured. */
116 (void) config_found(&sc->sc_dev, &npa, pcctwoprint);
117 }
118 }
119
120 int
121 pcctwoprint(aux, cp)
122 void *aux;
123 const char *cp;
124 {
125 struct pcctwo_attach_args *pa;
126
127 pa = aux;
128
129 if (cp)
130 aprint_normal("%s at %s", pa->pa_name, cp);
131
132 aprint_normal(" offset 0x%lx", pa->pa_offset - pa->_pa_base);
133 if (pa->pa_ipl != -1)
134 aprint_normal(" ipl %d", pa->pa_ipl);
135
136 return (UNCONF);
137 }
138
139 /*
140 * pcctwointr_establish: Establish PCCChip2 Interrupt
141 */
142 void
143 pcctwointr_establish(vec, hand, lvl, arg, evcnt)
144 int vec;
145 int (*hand) __P((void *)), lvl;
146 void *arg;
147 struct evcnt *evcnt;
148 {
149 int vec2icsr;
150
151 #ifdef DEBUG
152 if (vec < 0 || vec >= PCCTWOV_MAX) {
153 printf("pcctwo: illegal vector offset: 0x%x\n", vec);
154 panic("pcctwointr_establish");
155 }
156 if (lvl < 1 || lvl > 7) {
157 printf("pcctwo: illegal interrupt level: %d\n", lvl);
158 panic("pcctwointr_establish");
159 }
160 if (sys_pcctwo->sc_vec2icsr[vec] == -1) {
161 printf("pcctwo: unsupported vector: %d\n", vec);
162 panic("pcctwointr_establish");
163 }
164 #endif
165
166 vec2icsr = sys_pcctwo->sc_vec2icsr[vec];
167 pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr), 0);
168
169 /* Hook the interrupt */
170 (*sys_pcctwo->sc_isrlink)(sys_pcctwo->sc_isrcookie, hand, arg,
171 lvl, vec + sys_pcctwo->sc_vecbase, evcnt);
172
173 /* Enable it in hardware */
174 pcc2_reg_write(sys_pcctwo, VEC2ICSR_REG(vec2icsr),
175 VEC2ICSR_INIT(vec2icsr) | lvl);
176 }
177
178 void
179 pcctwointr_disestablish(vec)
180 int vec;
181 {
182
183 #ifdef DEBUG
184 if (vec < 0 || vec >= PCCTWOV_MAX) {
185 printf("pcctwo: illegal vector offset: 0x%x\n", vec);
186 panic("pcctwointr_disestablish");
187 }
188 if (sys_pcctwo->sc_vec2icsr[vec] == -1) {
189 printf("pcctwo: unsupported vector: %d\n", vec);
190 panic("pcctwointr_establish");
191 }
192 #endif
193
194 /* Disable it in hardware */
195 pcc2_reg_write(sys_pcctwo, sys_pcctwo->sc_vec2icsr[vec], 0);
196
197 (*sys_pcctwo->sc_isrunlink)(sys_pcctwo->sc_isrcookie,
198 vec + sys_pcctwo->sc_vecbase);
199 }
200
201 struct evcnt *
202 pcctwointr_evcnt(lev)
203 int lev;
204 {
205
206 return ((*sys_pcctwo->sc_isrevcnt)(sys_pcctwo->sc_isrcookie, lev));
207 }
208