px.c revision 1.6
1/* $NetBSD: px.c,v 1.6 2001/04/22 16:44:41 thorpej Exp $ */ 2 3/*- 4 * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 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 * Driver for DEC PixelStamp graphics adapters (PMAG-C). 41 */ 42 43#include <sys/param.h> 44#include <sys/types.h> 45#include <sys/systm.h> 46#include <sys/device.h> 47#include <sys/malloc.h> 48#include <sys/callout.h> 49 50#include <uvm/uvm_extern.h> 51 52#if defined(pmax) 53#include <mips/cpuregs.h> 54#elif defined(alpha) 55#include <alpha/alpha_cpu.h> 56#endif 57 58#include <machine/autoconf.h> 59#include <machine/cpu.h> 60#include <machine/bus.h> 61 62#include <dev/cons.h> 63 64#include <dev/wscons/wsconsio.h> 65#include <dev/wscons/wsdisplayvar.h> 66 67#include <dev/ic/bt459reg.h> 68 69#include <dev/tc/tcvar.h> 70#include <dev/tc/sticreg.h> 71#include <dev/tc/sticvar.h> 72 73#define PX_STIC_POLL_OFFSET 0x000000 /* STIC DMA poll space */ 74#define PX_STAMP_OFFSET 0x0c0000 /* pixelstamp space on STIC */ 75#define PX_STIC_OFFSET 0x180000 /* STIC registers */ 76#define PX_VDAC_OFFSET 0x200000 /* VDAC registers (bt459) */ 77#define PX_VDAC_RESET_OFFSET 0x300000 /* VDAC reset register */ 78#define PX_ROM_OFFSET 0x300000 /* ROM code */ 79 80#define PX_BUF_SIZE (STIC_PACKET_SIZE*2 + STIC_IMGBUF_SIZE*2) 81#define PX_BUF_ALIGN 32768 82 83static void px_attach(struct device *, struct device *, void *); 84static void px_init(struct stic_info *, int); 85static int px_match(struct device *, struct cfdata *, void *); 86 87static int px_intr(void *); 88static u_int32_t *px_pbuf_get(struct stic_info *); 89static int px_pbuf_post(struct stic_info *, u_int32_t *); 90 91void px_cnattach(tc_addr_t); 92 93struct px_softc { 94 struct device px_dv; 95 struct stic_info *px_si; 96}; 97 98struct cfattach px_ca = { 99 sizeof(struct px_softc), px_match, px_attach 100}; 101 102static int 103px_match(struct device *parent, struct cfdata *match, void *aux) 104{ 105 struct tc_attach_args *ta; 106 107 ta = aux; 108 109 return (strncmp("PMAG-CA ", ta->ta_modname, TC_ROM_LLEN) == 0); 110} 111 112static void 113px_attach(struct device *parent, struct device *self, void *aux) 114{ 115 struct stic_info *si; 116 struct tc_attach_args *ta; 117 struct px_softc *px; 118 int console; 119 120 px = (struct px_softc *)self; 121 ta = (struct tc_attach_args *)aux; 122 123 if (ta->ta_addr == stic_consinfo.si_slotbase) { 124 si = &stic_consinfo; 125 console = 1; 126 } else { 127 if (stic_consinfo.si_slotbase == NULL) 128 si = &stic_consinfo; 129 else { 130 si = malloc(sizeof(*si), M_DEVBUF, M_NOWAIT); 131 memset(si, 0, sizeof(*si)); 132 } 133 si->si_slotbase = ta->ta_addr; 134 px_init(si, 0); 135 console = 0; 136 } 137 138 px->px_si = si; 139 tc_intr_establish(parent, ta->ta_cookie, IPL_TTY, px_intr, si); 140 141 printf(": 2DA, 8 plane, %dx%d stamp\n", si->si_stampw, si->si_stamph); 142 143 stic_attach(self, si, console); 144} 145 146void 147px_cnattach(tc_addr_t addr) 148{ 149 struct stic_info *si; 150 151 si = &stic_consinfo; 152 si->si_slotbase = addr; 153 px_init(si, 1); 154 stic_cnattach(si); 155} 156 157static void 158px_init(struct stic_info *si, int bootstrap) 159{ 160 struct pglist pglist; 161 caddr_t kva; 162 paddr_t bpa; 163 164 /* 165 * Allocate memory for the packet buffers. It must be located below 166 * 8MB, since the STIC can't access outside that region. Also, due 167 * to the holes in STIC address space, each buffer mustn't cross a 168 * 32kB boundary. 169 */ 170 if (bootstrap) { 171 /* 172 * UVM won't be initalised at this point, so grab memory 173 * directly from vm_physmem[]. 174 */ 175 kva = (caddr_t)uvm_pageboot_alloc(PX_BUF_SIZE + PX_BUF_ALIGN); 176 bpa = (STIC_KSEG_TO_PHYS(kva) + PX_BUF_ALIGN - 1) & 177 ~(PX_BUF_ALIGN - 1); 178 if (bpa + PX_BUF_SIZE > 8192*1024) 179 panic("px_init: allocation out of bounds"); 180 } else { 181 TAILQ_INIT(&pglist); 182 if (uvm_pglistalloc(PX_BUF_SIZE, 0, 8192*1024, PX_BUF_ALIGN, 183 PX_BUF_ALIGN, &pglist, 1, 0) != 0) 184 panic("px_init: allocation failure"); 185 bpa = TAILQ_FIRST(&pglist)->phys_addr; 186 } 187 188 kva = (caddr_t)TC_PHYS_TO_UNCACHED(si->si_slotbase); 189 190 si->si_vdac = (u_int32_t *)(kva + PX_VDAC_OFFSET); 191 si->si_vdac_reset = (u_int32_t *)(kva + PX_VDAC_RESET_OFFSET); 192 si->si_stic = (volatile struct stic_regs *)(kva + PX_STIC_OFFSET); 193 si->si_stamp = (u_int32_t *)(kva + PX_STAMP_OFFSET); 194 si->si_buf = (u_int32_t *)TC_PHYS_TO_UNCACHED(bpa); 195 si->si_buf_phys = bpa; 196 si->si_buf_size = PX_BUF_SIZE; 197 si->si_disptype = WSDISPLAY_TYPE_PX; 198 si->si_depth = 8; 199 200 si->si_pbuf_get = px_pbuf_get; 201 si->si_pbuf_post = px_pbuf_post; 202 203 memset(si->si_buf, 0, PX_BUF_SIZE); 204 205 stic_init(si); 206} 207 208static int 209px_intr(void *cookie) 210{ 211 volatile struct stic_regs *sr; 212 struct stic_info *si; 213 int state; 214 215 si = cookie; 216 sr = si->si_stic; 217 state = sr->sr_ipdvint; 218 219 if ((state & STIC_INT_V) != 0) { 220 sr->sr_ipdvint = 221 STIC_INT_V_WE | (sr->sr_ipdvint & STIC_INT_V_EN); 222 tc_wmb(); 223 stic_flush(si); 224 } 225 226#ifdef DEBUG 227 if ((sr->sr_ipdvint & STIC_INT_E) != 0) { 228 printf("%s: error intr, %x %x %x %x %x", si->si_dv.dv_xname, 229 sr->sr_ipdvint, sr->sr_sticsr, sr->sr_buscsr, 230 sr->sr_busadr, sr->sr_busdat); 231 } 232#endif 233 234 return (1); 235} 236 237static u_int32_t * 238px_pbuf_get(struct stic_info *si) 239{ 240 241 si->si_pbuf_select ^= STIC_PACKET_SIZE; 242 return ((u_int32_t *)((caddr_t)si->si_buf + si->si_pbuf_select)); 243} 244 245static int 246px_pbuf_post(struct stic_info *si, u_int32_t *buf) 247{ 248 volatile u_int32_t *poll, junk; 249 volatile struct stic_regs *sr; 250 u_long v; 251 int c; 252 253 sr = si->si_stic; 254 255 /* Get address of poll register for this buffer. */ 256 v = (u_long)STIC_KSEG_TO_PHYS(buf); 257 v = ((v & 0xffff8000) << 3) | (v & 0x7fff); 258 poll = (volatile u_int32_t *)((caddr_t)si->si_slotbase + (v >> 9)); 259 260 /* 261 * Read the poll register and make sure the stamp wants to accept 262 * our packet. This read will initiate the DMA. Don't wait for 263 * ever, just in case something's wrong. 264 */ 265 tc_mb(); 266 267 for (c = STAMP_RETRIES; c != 0; c--) { 268 if ((sr->sr_ipdvint & STIC_INT_P) != 0) { 269 sr->sr_ipdvint = STIC_INT_P_WE | STIC_INT_P_EN; 270 tc_wmb(); 271 junk = *poll; 272 return (0); 273 } 274 DELAY(STAMP_DELAY); 275 } 276 277 /* STIC has lost the plot, punish it. */ 278 stic_reset(si); 279 return (-1); 280} 281