px.c revision 1.8 1 1.8 wiz /* $NetBSD: px.c,v 1.8 2001/09/18 18:15:54 wiz Exp $ */
2 1.1 jonathan
3 1.4 ad /*-
4 1.5 ad * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
5 1.1 jonathan * All rights reserved.
6 1.1 jonathan *
7 1.4 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.4 ad * by Andrew Doran.
9 1.4 ad *
10 1.1 jonathan * Redistribution and use in source and binary forms, with or without
11 1.1 jonathan * modification, are permitted provided that the following conditions
12 1.1 jonathan * are met:
13 1.1 jonathan * 1. Redistributions of source code must retain the above copyright
14 1.1 jonathan * notice, this list of conditions and the following disclaimer.
15 1.1 jonathan * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 jonathan * notice, this list of conditions and the following disclaimer in the
17 1.1 jonathan * documentation and/or other materials provided with the distribution.
18 1.1 jonathan * 3. All advertising materials mentioning features or use of this software
19 1.1 jonathan * must display the following acknowledgement:
20 1.4 ad * This product includes software developed by the NetBSD
21 1.4 ad * Foundation, Inc. and its contributors.
22 1.4 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.4 ad * contributors may be used to endorse or promote products derived
24 1.4 ad * from this software without specific prior written permission.
25 1.1 jonathan *
26 1.4 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.4 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.4 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.4 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.4 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.4 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.4 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.4 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.4 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.4 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.4 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.1 jonathan */
38 1.1 jonathan
39 1.1 jonathan /*
40 1.4 ad * Driver for DEC PixelStamp graphics adapters (PMAG-C).
41 1.1 jonathan */
42 1.1 jonathan
43 1.1 jonathan #include <sys/param.h>
44 1.4 ad #include <sys/types.h>
45 1.1 jonathan #include <sys/systm.h>
46 1.1 jonathan #include <sys/device.h>
47 1.4 ad #include <sys/malloc.h>
48 1.4 ad #include <sys/callout.h>
49 1.1 jonathan
50 1.4 ad #include <uvm/uvm_extern.h>
51 1.4 ad
52 1.4 ad #if defined(pmax)
53 1.4 ad #include <mips/cpuregs.h>
54 1.4 ad #elif defined(alpha)
55 1.4 ad #include <alpha/alpha_cpu.h>
56 1.4 ad #endif
57 1.1 jonathan
58 1.1 jonathan #include <machine/autoconf.h>
59 1.1 jonathan #include <machine/cpu.h>
60 1.1 jonathan #include <machine/bus.h>
61 1.1 jonathan
62 1.4 ad #include <dev/cons.h>
63 1.4 ad
64 1.4 ad #include <dev/wscons/wsconsio.h>
65 1.4 ad #include <dev/wscons/wsdisplayvar.h>
66 1.4 ad
67 1.4 ad #include <dev/ic/bt459reg.h>
68 1.4 ad
69 1.4 ad #include <dev/tc/tcvar.h>
70 1.4 ad #include <dev/tc/sticreg.h>
71 1.4 ad #include <dev/tc/sticvar.h>
72 1.4 ad
73 1.4 ad #define PX_STIC_POLL_OFFSET 0x000000 /* STIC DMA poll space */
74 1.4 ad #define PX_STAMP_OFFSET 0x0c0000 /* pixelstamp space on STIC */
75 1.4 ad #define PX_STIC_OFFSET 0x180000 /* STIC registers */
76 1.4 ad #define PX_VDAC_OFFSET 0x200000 /* VDAC registers (bt459) */
77 1.4 ad #define PX_VDAC_RESET_OFFSET 0x300000 /* VDAC reset register */
78 1.4 ad #define PX_ROM_OFFSET 0x300000 /* ROM code */
79 1.4 ad
80 1.4 ad #define PX_BUF_SIZE (STIC_PACKET_SIZE*2 + STIC_IMGBUF_SIZE*2)
81 1.4 ad #define PX_BUF_ALIGN 32768
82 1.4 ad
83 1.4 ad static void px_attach(struct device *, struct device *, void *);
84 1.4 ad static void px_init(struct stic_info *, int);
85 1.4 ad static int px_match(struct device *, struct cfdata *, void *);
86 1.4 ad
87 1.4 ad static int px_intr(void *);
88 1.4 ad static u_int32_t *px_pbuf_get(struct stic_info *);
89 1.4 ad static int px_pbuf_post(struct stic_info *, u_int32_t *);
90 1.1 jonathan
91 1.4 ad void px_cnattach(tc_addr_t);
92 1.1 jonathan
93 1.1 jonathan struct px_softc {
94 1.4 ad struct device px_dv;
95 1.4 ad struct stic_info *px_si;
96 1.1 jonathan };
97 1.1 jonathan
98 1.1 jonathan struct cfattach px_ca = {
99 1.4 ad sizeof(struct px_softc), px_match, px_attach
100 1.1 jonathan };
101 1.1 jonathan
102 1.4 ad static int
103 1.4 ad px_match(struct device *parent, struct cfdata *match, void *aux)
104 1.4 ad {
105 1.4 ad struct tc_attach_args *ta;
106 1.4 ad
107 1.4 ad ta = aux;
108 1.1 jonathan
109 1.4 ad return (strncmp("PMAG-CA ", ta->ta_modname, TC_ROM_LLEN) == 0);
110 1.1 jonathan }
111 1.1 jonathan
112 1.4 ad static void
113 1.4 ad px_attach(struct device *parent, struct device *self, void *aux)
114 1.4 ad {
115 1.4 ad struct stic_info *si;
116 1.4 ad struct tc_attach_args *ta;
117 1.4 ad struct px_softc *px;
118 1.4 ad int console;
119 1.4 ad
120 1.4 ad px = (struct px_softc *)self;
121 1.4 ad ta = (struct tc_attach_args *)aux;
122 1.4 ad
123 1.4 ad if (ta->ta_addr == stic_consinfo.si_slotbase) {
124 1.4 ad si = &stic_consinfo;
125 1.4 ad console = 1;
126 1.4 ad } else {
127 1.4 ad if (stic_consinfo.si_slotbase == NULL)
128 1.4 ad si = &stic_consinfo;
129 1.4 ad else {
130 1.4 ad si = malloc(sizeof(*si), M_DEVBUF, M_NOWAIT);
131 1.4 ad memset(si, 0, sizeof(*si));
132 1.4 ad }
133 1.4 ad si->si_slotbase = ta->ta_addr;
134 1.4 ad px_init(si, 0);
135 1.4 ad console = 0;
136 1.4 ad }
137 1.4 ad
138 1.4 ad px->px_si = si;
139 1.4 ad tc_intr_establish(parent, ta->ta_cookie, IPL_TTY, px_intr, si);
140 1.1 jonathan
141 1.7 ad printf(": 8 plane, %dx%d stamp\n", si->si_stampw, si->si_stamph);
142 1.1 jonathan
143 1.4 ad stic_attach(self, si, console);
144 1.4 ad }
145 1.1 jonathan
146 1.4 ad void
147 1.4 ad px_cnattach(tc_addr_t addr)
148 1.4 ad {
149 1.4 ad struct stic_info *si;
150 1.1 jonathan
151 1.4 ad si = &stic_consinfo;
152 1.4 ad si->si_slotbase = addr;
153 1.4 ad px_init(si, 1);
154 1.4 ad stic_cnattach(si);
155 1.1 jonathan }
156 1.4 ad
157 1.4 ad static void
158 1.4 ad px_init(struct stic_info *si, int bootstrap)
159 1.1 jonathan {
160 1.4 ad struct pglist pglist;
161 1.4 ad caddr_t kva;
162 1.4 ad paddr_t bpa;
163 1.4 ad
164 1.4 ad /*
165 1.4 ad * Allocate memory for the packet buffers. It must be located below
166 1.4 ad * 8MB, since the STIC can't access outside that region. Also, due
167 1.4 ad * to the holes in STIC address space, each buffer mustn't cross a
168 1.4 ad * 32kB boundary.
169 1.4 ad */
170 1.4 ad if (bootstrap) {
171 1.4 ad /*
172 1.8 wiz * UVM won't be initialised at this point, so grab memory
173 1.4 ad * directly from vm_physmem[].
174 1.4 ad */
175 1.6 thorpej kva = (caddr_t)uvm_pageboot_alloc(PX_BUF_SIZE + PX_BUF_ALIGN);
176 1.4 ad bpa = (STIC_KSEG_TO_PHYS(kva) + PX_BUF_ALIGN - 1) &
177 1.4 ad ~(PX_BUF_ALIGN - 1);
178 1.4 ad if (bpa + PX_BUF_SIZE > 8192*1024)
179 1.4 ad panic("px_init: allocation out of bounds");
180 1.4 ad } else {
181 1.4 ad TAILQ_INIT(&pglist);
182 1.4 ad if (uvm_pglistalloc(PX_BUF_SIZE, 0, 8192*1024, PX_BUF_ALIGN,
183 1.4 ad PX_BUF_ALIGN, &pglist, 1, 0) != 0)
184 1.4 ad panic("px_init: allocation failure");
185 1.4 ad bpa = TAILQ_FIRST(&pglist)->phys_addr;
186 1.4 ad }
187 1.4 ad
188 1.4 ad kva = (caddr_t)TC_PHYS_TO_UNCACHED(si->si_slotbase);
189 1.1 jonathan
190 1.4 ad si->si_vdac = (u_int32_t *)(kva + PX_VDAC_OFFSET);
191 1.4 ad si->si_vdac_reset = (u_int32_t *)(kva + PX_VDAC_RESET_OFFSET);
192 1.4 ad si->si_stic = (volatile struct stic_regs *)(kva + PX_STIC_OFFSET);
193 1.4 ad si->si_stamp = (u_int32_t *)(kva + PX_STAMP_OFFSET);
194 1.4 ad si->si_buf = (u_int32_t *)TC_PHYS_TO_UNCACHED(bpa);
195 1.4 ad si->si_buf_phys = bpa;
196 1.4 ad si->si_buf_size = PX_BUF_SIZE;
197 1.4 ad si->si_disptype = WSDISPLAY_TYPE_PX;
198 1.4 ad si->si_depth = 8;
199 1.1 jonathan
200 1.4 ad si->si_pbuf_get = px_pbuf_get;
201 1.4 ad si->si_pbuf_post = px_pbuf_post;
202 1.1 jonathan
203 1.4 ad memset(si->si_buf, 0, PX_BUF_SIZE);
204 1.4 ad
205 1.4 ad stic_init(si);
206 1.4 ad }
207 1.1 jonathan
208 1.4 ad static int
209 1.4 ad px_intr(void *cookie)
210 1.4 ad {
211 1.4 ad volatile struct stic_regs *sr;
212 1.4 ad struct stic_info *si;
213 1.4 ad int state;
214 1.4 ad
215 1.4 ad si = cookie;
216 1.4 ad sr = si->si_stic;
217 1.4 ad state = sr->sr_ipdvint;
218 1.4 ad
219 1.4 ad if ((state & STIC_INT_V) != 0) {
220 1.4 ad sr->sr_ipdvint =
221 1.4 ad STIC_INT_V_WE | (sr->sr_ipdvint & STIC_INT_V_EN);
222 1.1 jonathan tc_wmb();
223 1.4 ad stic_flush(si);
224 1.1 jonathan }
225 1.1 jonathan
226 1.4 ad #ifdef DEBUG
227 1.4 ad if ((sr->sr_ipdvint & STIC_INT_E) != 0) {
228 1.4 ad printf("%s: error intr, %x %x %x %x %x", si->si_dv.dv_xname,
229 1.4 ad sr->sr_ipdvint, sr->sr_sticsr, sr->sr_buscsr,
230 1.4 ad sr->sr_busadr, sr->sr_busdat);
231 1.4 ad }
232 1.1 jonathan #endif
233 1.1 jonathan
234 1.4 ad return (1);
235 1.1 jonathan }
236 1.1 jonathan
237 1.4 ad static u_int32_t *
238 1.4 ad px_pbuf_get(struct stic_info *si)
239 1.1 jonathan {
240 1.1 jonathan
241 1.4 ad si->si_pbuf_select ^= STIC_PACKET_SIZE;
242 1.4 ad return ((u_int32_t *)((caddr_t)si->si_buf + si->si_pbuf_select));
243 1.1 jonathan }
244 1.1 jonathan
245 1.4 ad static int
246 1.4 ad px_pbuf_post(struct stic_info *si, u_int32_t *buf)
247 1.1 jonathan {
248 1.5 ad volatile u_int32_t *poll, junk;
249 1.5 ad volatile struct stic_regs *sr;
250 1.4 ad u_long v;
251 1.4 ad int c;
252 1.4 ad
253 1.5 ad sr = si->si_stic;
254 1.5 ad
255 1.4 ad /* Get address of poll register for this buffer. */
256 1.4 ad v = (u_long)STIC_KSEG_TO_PHYS(buf);
257 1.4 ad v = ((v & 0xffff8000) << 3) | (v & 0x7fff);
258 1.5 ad poll = (volatile u_int32_t *)((caddr_t)si->si_slotbase + (v >> 9));
259 1.4 ad
260 1.4 ad /*
261 1.4 ad * Read the poll register and make sure the stamp wants to accept
262 1.4 ad * our packet. This read will initiate the DMA. Don't wait for
263 1.4 ad * ever, just in case something's wrong.
264 1.4 ad */
265 1.5 ad tc_mb();
266 1.4 ad
267 1.4 ad for (c = STAMP_RETRIES; c != 0; c--) {
268 1.5 ad if ((sr->sr_ipdvint & STIC_INT_P) != 0) {
269 1.5 ad sr->sr_ipdvint = STIC_INT_P_WE | STIC_INT_P_EN;
270 1.5 ad tc_wmb();
271 1.5 ad junk = *poll;
272 1.4 ad return (0);
273 1.5 ad }
274 1.4 ad DELAY(STAMP_DELAY);
275 1.4 ad }
276 1.1 jonathan
277 1.4 ad /* STIC has lost the plot, punish it. */
278 1.4 ad stic_reset(si);
279 1.4 ad return (-1);
280 1.1 jonathan }
281