px.c revision 1.26 1 1.26 christos /* $NetBSD: px.c,v 1.26 2005/12/11 12:24:00 christos 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.10 lukem
43 1.10 lukem #include <sys/cdefs.h>
44 1.26 christos __KERNEL_RCSID(0, "$NetBSD: px.c,v 1.26 2005/12/11 12:24:00 christos Exp $");
45 1.1 jonathan
46 1.1 jonathan #include <sys/param.h>
47 1.1 jonathan #include <sys/systm.h>
48 1.1 jonathan #include <sys/device.h>
49 1.4 ad #include <sys/malloc.h>
50 1.4 ad #include <sys/callout.h>
51 1.1 jonathan
52 1.4 ad #include <uvm/uvm_extern.h>
53 1.4 ad
54 1.4 ad #if defined(pmax)
55 1.4 ad #include <mips/cpuregs.h>
56 1.4 ad #elif defined(alpha)
57 1.4 ad #include <alpha/alpha_cpu.h>
58 1.4 ad #endif
59 1.1 jonathan
60 1.1 jonathan #include <machine/autoconf.h>
61 1.1 jonathan #include <machine/cpu.h>
62 1.1 jonathan #include <machine/bus.h>
63 1.1 jonathan
64 1.4 ad #include <dev/cons.h>
65 1.4 ad
66 1.4 ad #include <dev/wscons/wsconsio.h>
67 1.4 ad #include <dev/wscons/wsdisplayvar.h>
68 1.4 ad
69 1.4 ad #include <dev/ic/bt459reg.h>
70 1.4 ad
71 1.4 ad #include <dev/tc/tcvar.h>
72 1.4 ad #include <dev/tc/sticreg.h>
73 1.9 ad #include <dev/tc/sticio.h>
74 1.4 ad #include <dev/tc/sticvar.h>
75 1.4 ad
76 1.4 ad #define PX_STIC_POLL_OFFSET 0x000000 /* STIC DMA poll space */
77 1.4 ad #define PX_STAMP_OFFSET 0x0c0000 /* pixelstamp space on STIC */
78 1.4 ad #define PX_STIC_OFFSET 0x180000 /* STIC registers */
79 1.4 ad #define PX_VDAC_OFFSET 0x200000 /* VDAC registers (bt459) */
80 1.4 ad #define PX_VDAC_RESET_OFFSET 0x300000 /* VDAC reset register */
81 1.4 ad #define PX_ROM_OFFSET 0x300000 /* ROM code */
82 1.4 ad
83 1.9 ad #define PX_BUF_COUNT 16
84 1.9 ad #define PX_BUF_INC(x) ((x + 1) & (PX_BUF_COUNT - 1))
85 1.9 ad
86 1.9 ad /*
87 1.9 ad * We need enough aligned memory to hold:
88 1.9 ad *
89 1.9 ad * - Xserver communication area (4096 bytes)
90 1.9 ad * - 16 packet buffers (4096 bytes each)
91 1.9 ad * - 2 image buffers (5120 bytes each)
92 1.9 ad *
93 1.9 ad */
94 1.9 ad #define PX_BUF_SIZE \
95 1.9 ad (STIC_PACKET_SIZE * PX_BUF_COUNT + STIC_IMGBUF_SIZE*2 + STIC_XCOMM_SIZE)
96 1.4 ad #define PX_BUF_ALIGN 32768
97 1.4 ad
98 1.9 ad #define PXF_QUEUE 0x01
99 1.9 ad
100 1.9 ad void px_attach(struct device *, struct device *, void *);
101 1.9 ad void px_init(struct stic_info *, int);
102 1.26 christos int px_ioctl(struct stic_info *, u_long, caddr_t, int, struct lwp *);
103 1.9 ad int px_match(struct device *, struct cfdata *, void *);
104 1.9 ad
105 1.9 ad int px_intr(void *);
106 1.9 ad u_int32_t *px_pbuf_get(struct stic_info *);
107 1.9 ad int px_pbuf_post(struct stic_info *, u_int32_t *);
108 1.1 jonathan
109 1.4 ad void px_cnattach(tc_addr_t);
110 1.1 jonathan
111 1.1 jonathan struct px_softc {
112 1.4 ad struct device px_dv;
113 1.4 ad struct stic_info *px_si;
114 1.9 ad volatile u_int32_t *px_qpoll[PX_BUF_COUNT];
115 1.1 jonathan };
116 1.1 jonathan
117 1.16 thorpej CFATTACH_DECL(px, sizeof(struct px_softc),
118 1.17 thorpej px_match, px_attach, NULL, NULL);
119 1.1 jonathan
120 1.9 ad int
121 1.4 ad px_match(struct device *parent, struct cfdata *match, void *aux)
122 1.4 ad {
123 1.4 ad struct tc_attach_args *ta;
124 1.4 ad
125 1.4 ad ta = aux;
126 1.1 jonathan
127 1.4 ad return (strncmp("PMAG-CA ", ta->ta_modname, TC_ROM_LLEN) == 0);
128 1.1 jonathan }
129 1.1 jonathan
130 1.9 ad void
131 1.4 ad px_attach(struct device *parent, struct device *self, void *aux)
132 1.4 ad {
133 1.4 ad struct stic_info *si;
134 1.4 ad struct tc_attach_args *ta;
135 1.4 ad struct px_softc *px;
136 1.9 ad int console, i;
137 1.9 ad u_long v;
138 1.4 ad
139 1.4 ad px = (struct px_softc *)self;
140 1.4 ad ta = (struct tc_attach_args *)aux;
141 1.4 ad
142 1.4 ad if (ta->ta_addr == stic_consinfo.si_slotbase) {
143 1.4 ad si = &stic_consinfo;
144 1.4 ad console = 1;
145 1.4 ad } else {
146 1.20 mycroft if (stic_consinfo.si_slotbase == 0)
147 1.4 ad si = &stic_consinfo;
148 1.4 ad else {
149 1.12 tsutsui si = malloc(sizeof(*si), M_DEVBUF, M_NOWAIT|M_ZERO);
150 1.4 ad }
151 1.4 ad si->si_slotbase = ta->ta_addr;
152 1.4 ad px_init(si, 0);
153 1.4 ad console = 0;
154 1.4 ad }
155 1.4 ad
156 1.4 ad px->px_si = si;
157 1.9 ad si->si_dv = self;
158 1.4 ad tc_intr_establish(parent, ta->ta_cookie, IPL_TTY, px_intr, si);
159 1.1 jonathan
160 1.7 ad printf(": 8 plane, %dx%d stamp\n", si->si_stampw, si->si_stamph);
161 1.1 jonathan
162 1.9 ad for (i = 0; i < PX_BUF_COUNT; i++) {
163 1.9 ad v = i * STIC_PACKET_SIZE +
164 1.9 ad si->si_buf_phys + STIC_XCOMM_SIZE;
165 1.9 ad v = ((v & 0xffff8000) << 3) | (v & 0x7fff);
166 1.9 ad px->px_qpoll[i] = (volatile u_int32_t *)
167 1.9 ad ((caddr_t)si->si_slotbase + (v >> 9));
168 1.9 ad }
169 1.9 ad
170 1.4 ad stic_attach(self, si, console);
171 1.4 ad }
172 1.1 jonathan
173 1.4 ad void
174 1.4 ad px_cnattach(tc_addr_t addr)
175 1.4 ad {
176 1.4 ad struct stic_info *si;
177 1.1 jonathan
178 1.4 ad si = &stic_consinfo;
179 1.4 ad si->si_slotbase = addr;
180 1.4 ad px_init(si, 1);
181 1.4 ad stic_cnattach(si);
182 1.1 jonathan }
183 1.4 ad
184 1.9 ad void
185 1.4 ad px_init(struct stic_info *si, int bootstrap)
186 1.1 jonathan {
187 1.4 ad struct pglist pglist;
188 1.9 ad caddr_t kva, bva;
189 1.4 ad paddr_t bpa;
190 1.4 ad
191 1.21 chs kva = (caddr_t)si->si_slotbase;
192 1.21 chs
193 1.4 ad /*
194 1.4 ad * Allocate memory for the packet buffers. It must be located below
195 1.4 ad * 8MB, since the STIC can't access outside that region. Also, due
196 1.4 ad * to the holes in STIC address space, each buffer mustn't cross a
197 1.4 ad * 32kB boundary.
198 1.4 ad */
199 1.4 ad if (bootstrap) {
200 1.23 perry /*
201 1.8 wiz * UVM won't be initialised at this point, so grab memory
202 1.4 ad * directly from vm_physmem[].
203 1.4 ad */
204 1.9 ad bva = (caddr_t)uvm_pageboot_alloc(PX_BUF_SIZE + PX_BUF_ALIGN);
205 1.22 mhitch bpa = (STIC_KSEG_TO_PHYS(bva) + PX_BUF_ALIGN - 1) &
206 1.4 ad ~(PX_BUF_ALIGN - 1);
207 1.4 ad if (bpa + PX_BUF_SIZE > 8192*1024)
208 1.4 ad panic("px_init: allocation out of bounds");
209 1.4 ad } else {
210 1.9 ad if (uvm_pglistalloc(PX_BUF_SIZE, 0, 8192*1024, PX_BUF_ALIGN,
211 1.9 ad 0, &pglist, 1, 0) != 0)
212 1.4 ad panic("px_init: allocation failure");
213 1.25 yamt bpa = VM_PAGE_TO_PHYS(TAILQ_FIRST(&pglist));
214 1.4 ad }
215 1.1 jonathan
216 1.4 ad si->si_vdac = (u_int32_t *)(kva + PX_VDAC_OFFSET);
217 1.4 ad si->si_vdac_reset = (u_int32_t *)(kva + PX_VDAC_RESET_OFFSET);
218 1.4 ad si->si_stic = (volatile struct stic_regs *)(kva + PX_STIC_OFFSET);
219 1.4 ad si->si_stamp = (u_int32_t *)(kva + PX_STAMP_OFFSET);
220 1.4 ad si->si_buf = (u_int32_t *)TC_PHYS_TO_UNCACHED(bpa);
221 1.9 ad si->si_buf_phys = bpa;
222 1.4 ad si->si_buf_size = PX_BUF_SIZE;
223 1.4 ad si->si_disptype = WSDISPLAY_TYPE_PX;
224 1.4 ad si->si_depth = 8;
225 1.9 ad si->si_sxc = (volatile struct stic_xcomm *)si->si_buf;
226 1.1 jonathan
227 1.4 ad si->si_pbuf_get = px_pbuf_get;
228 1.4 ad si->si_pbuf_post = px_pbuf_post;
229 1.9 ad si->si_ioctl = px_ioctl;
230 1.1 jonathan
231 1.4 ad memset(si->si_buf, 0, PX_BUF_SIZE);
232 1.4 ad
233 1.4 ad stic_init(si);
234 1.4 ad }
235 1.1 jonathan
236 1.9 ad int
237 1.4 ad px_intr(void *cookie)
238 1.4 ad {
239 1.4 ad volatile struct stic_regs *sr;
240 1.9 ad volatile struct stic_xcomm *sxc;
241 1.4 ad struct stic_info *si;
242 1.9 ad struct px_softc *px;
243 1.4 ad int state;
244 1.4 ad
245 1.4 ad si = cookie;
246 1.9 ad px = (struct px_softc *)si->si_dv;
247 1.4 ad sr = si->si_stic;
248 1.4 ad state = sr->sr_ipdvint;
249 1.9 ad sxc = si->si_sxc;
250 1.4 ad
251 1.9 ad /*
252 1.9 ad * Vertical-retrace condition.
253 1.9 ad *
254 1.9 ad * Clear the flag and flush out any waiting VDAC updates. We do
255 1.9 ad * this at retrace time to avoid producing `shearing' and other
256 1.9 ad * nasty artifacts.
257 1.23 perry */
258 1.4 ad if ((state & STIC_INT_V) != 0) {
259 1.9 ad sr->sr_ipdvint = STIC_INT_V_WE | STIC_INT_V_EN;
260 1.1 jonathan tc_wmb();
261 1.4 ad stic_flush(si);
262 1.1 jonathan }
263 1.1 jonathan
264 1.9 ad /*
265 1.9 ad * Error condition.
266 1.9 ad *
267 1.9 ad * Simply clear the flag and report the error.
268 1.9 ad */
269 1.9 ad if ((state & STIC_INT_E) != 0) {
270 1.9 ad printf("%s: error intr, %x %x %x %x %x", px->px_dv.dv_xname,
271 1.4 ad sr->sr_ipdvint, sr->sr_sticsr, sr->sr_buscsr,
272 1.4 ad sr->sr_busadr, sr->sr_busdat);
273 1.9 ad sr->sr_ipdvint = STIC_INT_E_WE | STIC_INT_E_EN;
274 1.9 ad tc_wmb();
275 1.9 ad }
276 1.9 ad
277 1.9 ad /*
278 1.9 ad * Check for queue stalls.
279 1.9 ad */
280 1.9 ad if (sxc->sxc_tail != sxc->sxc_head && !sxc->sxc_busy)
281 1.9 ad state |= STIC_INT_P;
282 1.9 ad
283 1.9 ad /*
284 1.9 ad * Packet-done condition.
285 1.9 ad *
286 1.9 ad * If packet queueing is enabled, clear the condition, and increment
287 1.9 ad * the tail (submitted) pointer.
288 1.9 ad */
289 1.9 ad if ((si->si_hwflags & PXF_QUEUE) != 0 && (state & STIC_INT_P) != 0) {
290 1.9 ad sr->sr_ipdvint = STIC_INT_P_WE | STIC_INT_P_EN;
291 1.9 ad tc_wmb();
292 1.9 ad
293 1.9 ad if (sxc->sxc_tail != sxc->sxc_head) {
294 1.9 ad sxc->sxc_done[sxc->sxc_tail] = 0;
295 1.9 ad sxc->sxc_tail = PX_BUF_INC(sxc->sxc_tail);
296 1.9 ad }
297 1.9 ad
298 1.9 ad if (sxc->sxc_tail != sxc->sxc_head) {
299 1.9 ad if (*px->px_qpoll[sxc->sxc_tail] != STAMP_OK) {
300 1.9 ad sxc->sxc_nreject++;
301 1.9 ad sxc->sxc_busy = 0;
302 1.9 ad } else
303 1.9 ad sxc->sxc_busy = 1;
304 1.9 ad } else
305 1.9 ad sxc->sxc_busy = 0;
306 1.4 ad }
307 1.9 ad
308 1.9 ad if ((si->si_hwflags & PXF_QUEUE) != 0 && (state & STIC_INT_P_EN) == 0)
309 1.9 ad printf("px_intr: STIC_INT_P_EN == 0\n");
310 1.1 jonathan
311 1.4 ad return (1);
312 1.1 jonathan }
313 1.1 jonathan
314 1.9 ad u_int32_t *
315 1.4 ad px_pbuf_get(struct stic_info *si)
316 1.1 jonathan {
317 1.9 ad u_long off;
318 1.1 jonathan
319 1.4 ad si->si_pbuf_select ^= STIC_PACKET_SIZE;
320 1.9 ad off = si->si_pbuf_select + STIC_XCOMM_SIZE;
321 1.9 ad return ((u_int32_t *)((caddr_t)si->si_buf + off));
322 1.1 jonathan }
323 1.1 jonathan
324 1.9 ad int
325 1.4 ad px_pbuf_post(struct stic_info *si, u_int32_t *buf)
326 1.1 jonathan {
327 1.5 ad volatile u_int32_t *poll, junk;
328 1.5 ad volatile struct stic_regs *sr;
329 1.4 ad u_long v;
330 1.4 ad int c;
331 1.4 ad
332 1.5 ad sr = si->si_stic;
333 1.5 ad
334 1.4 ad /* Get address of poll register for this buffer. */
335 1.4 ad v = (u_long)STIC_KSEG_TO_PHYS(buf);
336 1.4 ad v = ((v & 0xffff8000) << 3) | (v & 0x7fff);
337 1.5 ad poll = (volatile u_int32_t *)((caddr_t)si->si_slotbase + (v >> 9));
338 1.4 ad
339 1.4 ad /*
340 1.4 ad * Read the poll register and make sure the stamp wants to accept
341 1.4 ad * our packet. This read will initiate the DMA. Don't wait for
342 1.4 ad * ever, just in case something's wrong.
343 1.4 ad */
344 1.5 ad tc_mb();
345 1.4 ad
346 1.4 ad for (c = STAMP_RETRIES; c != 0; c--) {
347 1.5 ad if ((sr->sr_ipdvint & STIC_INT_P) != 0) {
348 1.9 ad sr->sr_ipdvint = STIC_INT_P_WE;
349 1.5 ad tc_wmb();
350 1.5 ad junk = *poll;
351 1.4 ad return (0);
352 1.5 ad }
353 1.4 ad DELAY(STAMP_DELAY);
354 1.4 ad }
355 1.1 jonathan
356 1.4 ad /* STIC has lost the plot, punish it. */
357 1.4 ad stic_reset(si);
358 1.4 ad return (-1);
359 1.9 ad }
360 1.9 ad
361 1.9 ad int
362 1.9 ad px_ioctl(struct stic_info *si, u_long cmd, caddr_t data, int flag,
363 1.26 christos struct lwp *l)
364 1.9 ad {
365 1.9 ad volatile struct stic_xcomm *sxc;
366 1.9 ad volatile struct stic_regs *sr;
367 1.9 ad struct stic_xinfo *sxi;
368 1.9 ad int rv, s;
369 1.9 ad
370 1.9 ad sr = si->si_stic;
371 1.9 ad
372 1.9 ad switch (cmd) {
373 1.9 ad case STICIO_STARTQ:
374 1.9 ad if (si->si_dispmode != WSDISPLAYIO_MODE_MAPPED ||
375 1.9 ad (si->si_hwflags & PXF_QUEUE) != 0) {
376 1.9 ad rv = EBUSY;
377 1.9 ad break;
378 1.9 ad }
379 1.9 ad
380 1.9 ad sxc = si->si_sxc;
381 1.24 he memset((void *)__UNVOLATILE(sxc->sxc_done), 0,
382 1.24 he sizeof(sxc->sxc_done));
383 1.9 ad sxc->sxc_head = 0;
384 1.9 ad sxc->sxc_tail = 0;
385 1.9 ad sxc->sxc_nreject = 0;
386 1.9 ad sxc->sxc_nstall = 0;
387 1.9 ad
388 1.9 ad s = spltty();
389 1.9 ad si->si_hwflags |= PXF_QUEUE;
390 1.9 ad sr->sr_ipdvint = STIC_INT_P_WE | STIC_INT_P_EN;
391 1.9 ad tc_wmb();
392 1.9 ad splx(s);
393 1.9 ad
394 1.9 ad rv = 0;
395 1.9 ad break;
396 1.9 ad
397 1.9 ad case STICIO_STOPQ:
398 1.9 ad s = spltty();
399 1.9 ad si->si_hwflags &= ~PXF_QUEUE;
400 1.9 ad sr->sr_ipdvint = STIC_INT_P_WE | STIC_INT_P;
401 1.9 ad tc_wmb();
402 1.9 ad splx(s);
403 1.9 ad rv = 0;
404 1.9 ad break;
405 1.9 ad
406 1.9 ad case STICIO_GXINFO:
407 1.9 ad sxi = (struct stic_xinfo *)data;
408 1.9 ad sxi->sxi_unit = si->si_unit;
409 1.9 ad sxi->sxi_stampw = si->si_stampw;
410 1.9 ad sxi->sxi_stamph = si->si_stamph;
411 1.9 ad sxi->sxi_buf_size = si->si_buf_size;
412 1.9 ad sxi->sxi_buf_phys = (u_int)si->si_buf_phys;
413 1.9 ad sxi->sxi_buf_pktoff = STIC_XCOMM_SIZE;
414 1.9 ad sxi->sxi_buf_pktcnt = PX_BUF_COUNT;
415 1.9 ad sxi->sxi_buf_imgoff =
416 1.9 ad STIC_XCOMM_SIZE + STIC_PACKET_SIZE * PX_BUF_COUNT;
417 1.9 ad rv = 0;
418 1.9 ad break;
419 1.9 ad
420 1.9 ad default:
421 1.13 atatat rv = EPASSTHROUGH;
422 1.9 ad break;
423 1.9 ad }
424 1.9 ad
425 1.9 ad return (rv);
426 1.1 jonathan }
427