Home | History | Annotate | Line # | Download | only in tc
pxg.c revision 1.4
      1  1.4  ad /* 	$NetBSD: pxg.c,v 1.4 2001/03/04 13:32:25 ad Exp $	*/
      2  1.1  ad 
      3  1.1  ad /*-
      4  1.3  ad  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
      5  1.1  ad  * All rights reserved.
      6  1.1  ad  *
      7  1.1  ad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  ad  * by Andrew Doran.
      9  1.1  ad  *
     10  1.1  ad  * Redistribution and use in source and binary forms, with or without
     11  1.1  ad  * modification, are permitted provided that the following conditions
     12  1.1  ad  * are met:
     13  1.1  ad  * 1. Redistributions of source code must retain the above copyright
     14  1.1  ad  *    notice, this list of conditions and the following disclaimer.
     15  1.1  ad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  ad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  ad  *    documentation and/or other materials provided with the distribution.
     18  1.1  ad  * 3. All advertising materials mentioning features or use of this software
     19  1.1  ad  *    must display the following acknowledgement:
     20  1.1  ad  *	This product includes software developed by the NetBSD
     21  1.1  ad  *	Foundation, Inc. and its contributors.
     22  1.1  ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  ad  *    contributors may be used to endorse or promote products derived
     24  1.1  ad  *    from this software without specific prior written permission.
     25  1.1  ad  *
     26  1.1  ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  ad  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  ad  */
     38  1.1  ad 
     39  1.1  ad /*
     40  1.1  ad  * Driver for DEC PixelStamp graphics accelerators with onboard SRAM and
     41  1.1  ad  * Intel i860 co-processor (PMAG-D, E and F).
     42  1.1  ad  */
     43  1.1  ad 
     44  1.1  ad #include <sys/param.h>
     45  1.1  ad #include <sys/types.h>
     46  1.1  ad #include <sys/systm.h>
     47  1.1  ad #include <sys/device.h>
     48  1.1  ad #include <sys/malloc.h>
     49  1.1  ad #include <sys/callout.h>
     50  1.2  ad #include <sys/proc.h>
     51  1.1  ad 
     52  1.1  ad #if defined(pmax)
     53  1.1  ad #include <mips/cpuregs.h>
     54  1.1  ad #elif defined(alpha)
     55  1.1  ad #include <alpha/alpha_cpu.h>
     56  1.1  ad #endif
     57  1.1  ad 
     58  1.1  ad #include <machine/autoconf.h>
     59  1.1  ad #include <machine/cpu.h>
     60  1.1  ad #include <machine/bus.h>
     61  1.1  ad 
     62  1.1  ad #include <dev/cons.h>
     63  1.1  ad 
     64  1.1  ad #include <dev/wscons/wsconsio.h>
     65  1.1  ad #include <dev/wscons/wsdisplayvar.h>
     66  1.1  ad 
     67  1.1  ad #include <dev/ic/bt459reg.h>
     68  1.1  ad 
     69  1.1  ad #include <dev/tc/tcvar.h>
     70  1.1  ad #include <dev/tc/sticreg.h>
     71  1.1  ad #include <dev/tc/sticvar.h>
     72  1.1  ad 
     73  1.1  ad #define	PXG_STIC_POLL_OFFSET	0x000000	/* STIC DMA poll space */
     74  1.1  ad #define	PXG_STAMP_OFFSET	0x0c0000	/* pixelstamp space on STIC */
     75  1.1  ad #define	PXG_STIC_OFFSET		0x180000	/* STIC registers */
     76  1.3  ad #define	PXG_SRAM_OFFSET		0x200000	/* 128 or 256kB of SRAM */
     77  1.2  ad #define	PXG_HOST_INTR_OFFSET	0x280000	/* i860 host interrupt */
     78  1.2  ad #define	PXG_COPROC_INTR_OFFSET	0x2c0000	/* i860 coprocessor interrupt */
     79  1.1  ad #define	PXG_VDAC_OFFSET		0x300000	/* VDAC registers (bt459) */
     80  1.1  ad #define	PXG_VDAC_RESET_OFFSET	0x340000	/* VDAC reset register */
     81  1.1  ad #define	PXG_ROM_OFFSET		0x380000	/* ROM code */
     82  1.2  ad #define	PXG_I860_START_OFFSET	0x380000	/* i860 start register */
     83  1.2  ad #define	PXG_I860_RESET_OFFSET	0x3c0000	/* i860 stop register */
     84  1.1  ad 
     85  1.1  ad static void	pxg_attach(struct device *, struct device *, void *);
     86  1.1  ad static int	pxg_intr(void *);
     87  1.1  ad static int	pxg_match(struct device *, struct cfdata *, void *);
     88  1.1  ad 
     89  1.1  ad static void	pxg_init(struct stic_info *);
     90  1.2  ad static int	pxg_ioctl(struct stic_info *, u_long, caddr_t, int,
     91  1.2  ad 			  struct proc *);
     92  1.1  ad static u_int32_t	*pxg_pbuf_get(struct stic_info *);
     93  1.1  ad static int	pxg_pbuf_post(struct stic_info *, u_int32_t *);
     94  1.1  ad static int	pxg_probe_planes(struct stic_info *);
     95  1.1  ad static int	pxg_probe_sram(struct stic_info *);
     96  1.1  ad 
     97  1.1  ad void	pxg_cnattach(tc_addr_t);
     98  1.1  ad 
     99  1.1  ad struct pxg_softc {
    100  1.1  ad 	struct	device pxg_dv;
    101  1.1  ad 	struct	stic_info *pxg_si;
    102  1.1  ad };
    103  1.1  ad 
    104  1.1  ad struct cfattach pxg_ca = {
    105  1.1  ad 	sizeof(struct pxg_softc), pxg_match, pxg_attach
    106  1.1  ad };
    107  1.1  ad 
    108  1.1  ad static const char *pxg_types[] = {
    109  1.1  ad 	"PMAG-DA ", "LM-3DA",
    110  1.1  ad 	"PMAG-FA ", "HE-3DA",
    111  1.1  ad 	"PMAG-FB ", "HE+3DA",
    112  1.1  ad 	"PMAGB-FA", "HE+3DA",
    113  1.1  ad 	"PMAGB-FB", "HE+3DA",
    114  1.1  ad };
    115  1.1  ad 
    116  1.1  ad static int
    117  1.1  ad pxg_match(struct device *parent, struct cfdata *match, void *aux)
    118  1.1  ad {
    119  1.1  ad 	struct tc_attach_args *ta;
    120  1.1  ad 	int i;
    121  1.1  ad 
    122  1.1  ad 	ta = aux;
    123  1.1  ad 
    124  1.1  ad 	for (i = 0; i < sizeof(pxg_types) / sizeof(pxg_types[0]); i += 2)
    125  1.1  ad 		if (strncmp(pxg_types[i], ta->ta_modname, TC_ROM_LLEN) == 0)
    126  1.1  ad 			return (1);
    127  1.1  ad 
    128  1.1  ad 	return (0);
    129  1.1  ad }
    130  1.1  ad 
    131  1.1  ad static void
    132  1.1  ad pxg_attach(struct device *parent, struct device *self, void *aux)
    133  1.1  ad {
    134  1.1  ad 	struct stic_info *si;
    135  1.1  ad 	struct tc_attach_args *ta;
    136  1.1  ad 	struct pxg_softc *pxg;
    137  1.1  ad 	int console, i;
    138  1.1  ad 
    139  1.1  ad 	pxg = (struct pxg_softc *)self;
    140  1.1  ad 	ta = (struct tc_attach_args *)aux;
    141  1.1  ad 
    142  1.1  ad 	if (ta->ta_addr == stic_consinfo.si_slotbase) {
    143  1.1  ad 		si = &stic_consinfo;
    144  1.1  ad 		console = 1;
    145  1.1  ad 	} else {
    146  1.1  ad 		if (stic_consinfo.si_slotbase == NULL)
    147  1.1  ad 			si = &stic_consinfo;
    148  1.1  ad 		else {
    149  1.1  ad 			si = malloc(sizeof(*si), M_DEVBUF, M_NOWAIT);
    150  1.1  ad 			memset(si, 0, sizeof(*si));
    151  1.1  ad 		}
    152  1.1  ad 		si->si_slotbase = ta->ta_addr;
    153  1.1  ad 		pxg_init(si);
    154  1.1  ad 		console = 0;
    155  1.1  ad 	}
    156  1.1  ad 
    157  1.1  ad 	pxg->pxg_si = si;
    158  1.1  ad 	tc_intr_establish(parent, ta->ta_cookie, IPL_TTY, pxg_intr, si);
    159  1.1  ad 
    160  1.1  ad 	for (i = 0; i < sizeof(pxg_types) / sizeof(pxg_types[0]); i += 2)
    161  1.1  ad 		if (strncmp(pxg_types[i], ta->ta_modname, TC_ROM_LLEN) == 0)
    162  1.1  ad 			break;
    163  1.1  ad 
    164  1.1  ad 	printf(": %s, %d plane, %dx%d stamp, %dkB SRAM\n", pxg_types[i + 1],
    165  1.4  ad 	    si->si_depth, si->si_stampw, si->si_stamph,
    166  1.4  ad 	    (int)si->si_buf_size >> 10);
    167  1.1  ad 
    168  1.1  ad 	stic_attach(self, si, console);
    169  1.1  ad }
    170  1.1  ad 
    171  1.1  ad void
    172  1.1  ad pxg_cnattach(tc_addr_t addr)
    173  1.1  ad {
    174  1.1  ad 	struct stic_info *si;
    175  1.1  ad 
    176  1.1  ad 	si = &stic_consinfo;
    177  1.1  ad 	si->si_slotbase = addr;
    178  1.1  ad 	pxg_init(si);
    179  1.1  ad 	stic_cnattach(si);
    180  1.1  ad }
    181  1.1  ad 
    182  1.1  ad static void
    183  1.1  ad pxg_init(struct stic_info *si)
    184  1.1  ad {
    185  1.1  ad 	volatile u_int32_t *slot;
    186  1.1  ad 	caddr_t kva;
    187  1.1  ad 
    188  1.4  ad 	kva = (caddr_t)si->si_slotbase;
    189  1.1  ad 
    190  1.1  ad 	si->si_vdac = (u_int32_t *)(kva + PXG_VDAC_OFFSET);
    191  1.1  ad 	si->si_vdac_reset = (u_int32_t *)(kva + PXG_VDAC_RESET_OFFSET);
    192  1.1  ad 	si->si_stic = (volatile struct stic_regs *)(kva + PXG_STIC_OFFSET);
    193  1.1  ad 	si->si_stamp = (u_int32_t *)(kva + PXG_STAMP_OFFSET);
    194  1.4  ad 	si->si_buf = (u_int32_t *)(kva + PXG_SRAM_OFFSET);
    195  1.4  ad 	si->si_buf_phys = STIC_KSEG_TO_PHYS(si->si_buf);
    196  1.1  ad 	si->si_buf_size = pxg_probe_sram(si);
    197  1.1  ad 	si->si_disptype = WSDISPLAY_TYPE_PXG;
    198  1.1  ad 
    199  1.1  ad 	si->si_pbuf_get = pxg_pbuf_get;
    200  1.1  ad 	si->si_pbuf_post = pxg_pbuf_post;
    201  1.2  ad 	si->si_ioctl = pxg_ioctl;
    202  1.1  ad 
    203  1.1  ad 	/* Disable the co-processor. */
    204  1.4  ad 	slot = (volatile u_int32_t *)kva;
    205  1.2  ad 	slot[PXG_I860_RESET_OFFSET >> 2] = 0;
    206  1.4  ad 	tc_wmb();
    207  1.1  ad 	slot[PXG_HOST_INTR_OFFSET >> 2] = 0;
    208  1.4  ad 	tc_wmb();
    209  1.1  ad 	tc_syncbus();
    210  1.1  ad 	DELAY(40000);
    211  1.1  ad 
    212  1.1  ad 	/* XXX Check for a second PixelStamp. */
    213  1.1  ad 	if (((si->si_stic->sr_modcl & 0x600) >> 9) > 1)
    214  1.1  ad 		si->si_depth = 24;
    215  1.1  ad 	else
    216  1.1  ad 		si->si_depth = pxg_probe_planes(si);
    217  1.1  ad 
    218  1.1  ad 	stic_init(si);
    219  1.1  ad }
    220  1.1  ad 
    221  1.1  ad static int
    222  1.1  ad pxg_probe_sram(struct stic_info *si)
    223  1.1  ad {
    224  1.1  ad 	volatile u_int32_t *a, *b;
    225  1.1  ad 
    226  1.4  ad 	a = (volatile u_int32_t *)si->si_slotbase + (PXG_SRAM_OFFSET >> 2);
    227  1.4  ad 	b = a + (0x20000 >> 2);
    228  1.1  ad 	*a = 4321;
    229  1.1  ad 	*b = 1234;
    230  1.4  ad 	tc_mb();
    231  1.1  ad 	return ((*a == *b) ? 0x20000 : 0x40000);
    232  1.1  ad }
    233  1.1  ad 
    234  1.1  ad static int
    235  1.1  ad pxg_probe_planes(struct stic_info *si)
    236  1.1  ad {
    237  1.1  ad 	volatile u_int32_t *vdac;
    238  1.1  ad 	int id;
    239  1.1  ad 
    240  1.1  ad 	/*
    241  1.1  ad 	 * For the visible framebuffer (# 0), we can cheat and use the VDAC
    242  1.1  ad 	 * ID.
    243  1.1  ad 	 */
    244  1.1  ad 	vdac = si->si_vdac;
    245  1.1  ad 	vdac[BT459_REG_ADDR_LOW] = (BT459_IREG_ID & 0xff) |
    246  1.1  ad 	    ((BT459_IREG_ID & 0xff) << 8) | ((BT459_IREG_ID & 0xff) << 16);
    247  1.1  ad 	vdac[BT459_REG_ADDR_HIGH] = ((BT459_IREG_ID & 0xff00) >> 8) |
    248  1.1  ad 	    (BT459_IREG_ID & 0xff00) | ((BT459_IREG_ID & 0xff00) << 8);
    249  1.4  ad 	tc_mb();
    250  1.1  ad 	id = vdac[BT459_REG_IREG_DATA] & 0x00ffffff;
    251  1.1  ad 
    252  1.1  ad 	/* 3 VDACs */
    253  1.1  ad 	if (id == 0x004a4a4a)
    254  1.1  ad 		return (24);
    255  1.1  ad 
    256  1.1  ad 	/* 1 VDAC */
    257  1.1  ad 	if ((id & 0xff0000) == 0x4a0000 || (id & 0x00ff00) == 0x004a00 ||
    258  1.1  ad 	    (id & 0x0000ff) == 0x00004a)
    259  1.1  ad 		return (8);
    260  1.1  ad 
    261  1.1  ad 	/* XXX Assume 8 planes. */
    262  1.1  ad 	printf("pxg_probe_planes: invalid VDAC ID %x\n", id);
    263  1.1  ad 	return (8);
    264  1.1  ad }
    265  1.1  ad 
    266  1.1  ad static int
    267  1.1  ad pxg_intr(void *cookie)
    268  1.1  ad {
    269  1.1  ad 	struct stic_info *si;
    270  1.1  ad 	volatile struct stic_regs *sr;
    271  1.1  ad 	volatile u_int32_t *hi;
    272  1.1  ad 	u_int32_t state;
    273  1.1  ad 	int it;
    274  1.1  ad 
    275  1.1  ad 	si = cookie;
    276  1.1  ad 	sr = si->si_stic;
    277  1.1  ad 	state = sr->sr_ipdvint;
    278  1.4  ad 	hi = (volatile u_int32_t *)si->si_slotbase +
    279  1.4  ad 	    (PXG_HOST_INTR_OFFSET / sizeof(u_int32_t));
    280  1.1  ad 
    281  1.1  ad 	/* Clear the interrupt condition */
    282  1.1  ad 	it = hi[0] & 15;
    283  1.1  ad 	hi[0] = 0;
    284  1.1  ad 	tc_wmb();
    285  1.1  ad 	hi[2] = 0;
    286  1.1  ad 	tc_wmb();
    287  1.1  ad 
    288  1.1  ad 	/*
    289  1.3  ad 	 * On the PXG, STIC interrupts are posted to the co-processor.
    290  1.3  ad 	 * Since we don't yet run it, this code is useless.
    291  1.1  ad 	 */
    292  1.1  ad 	if (it == 3) {
    293  1.1  ad 		sr->sr_ipdvint =
    294  1.1  ad 		    STIC_INT_V_WE | (sr->sr_ipdvint & STIC_INT_V_EN);
    295  1.1  ad 		tc_wmb();
    296  1.1  ad 		stic_flush(si);
    297  1.1  ad 	}
    298  1.1  ad 
    299  1.1  ad 	return (1);
    300  1.1  ad }
    301  1.1  ad 
    302  1.1  ad static u_int32_t *
    303  1.1  ad pxg_pbuf_get(struct stic_info *si)
    304  1.1  ad {
    305  1.1  ad 
    306  1.1  ad 	si->si_pbuf_select ^= STIC_PACKET_SIZE;
    307  1.1  ad 	return ((u_int32_t *)((caddr_t)si->si_buf + si->si_pbuf_select));
    308  1.1  ad }
    309  1.1  ad 
    310  1.1  ad static int
    311  1.1  ad pxg_pbuf_post(struct stic_info *si, u_int32_t *buf)
    312  1.1  ad {
    313  1.4  ad 	volatile u_int32_t *poll, junk;
    314  1.4  ad 	volatile struct stic_regs *sr;
    315  1.1  ad 	u_long v;
    316  1.1  ad 	int c;
    317  1.1  ad 
    318  1.4  ad 	sr = si->si_stic;
    319  1.4  ad 
    320  1.1  ad 	/* Get address of poll register for this buffer. */
    321  1.1  ad 	v = ((u_long)buf - (u_long)si->si_buf) >> 9;
    322  1.4  ad 	poll = (volatile u_int32_t *)((caddr_t)si->si_slotbase + v);
    323  1.1  ad 
    324  1.1  ad 	/*
    325  1.1  ad 	 * Read the poll register and make sure the stamp wants to accept
    326  1.1  ad 	 * our packet.  This read will initiate the DMA.  Don't wait for
    327  1.1  ad 	 * ever, just in case something's wrong.
    328  1.1  ad 	 */
    329  1.4  ad 	tc_mb();
    330  1.1  ad 
    331  1.1  ad 	for (c = STAMP_RETRIES; c != 0; c--) {
    332  1.4  ad 		if ((sr->sr_ipdvint & STIC_INT_P) != 0) {
    333  1.4  ad 			sr->sr_ipdvint = STIC_INT_P_WE | STIC_INT_P_EN;
    334  1.4  ad 			tc_wmb();
    335  1.4  ad 			junk = *poll;
    336  1.3  ad 			return (0);
    337  1.4  ad 		}
    338  1.1  ad 		DELAY(STAMP_DELAY);
    339  1.1  ad 	}
    340  1.1  ad 
    341  1.1  ad 	/* STIC has lost the plot, punish it. */
    342  1.1  ad 	stic_reset(si);
    343  1.1  ad 	return (-1);
    344  1.2  ad }
    345  1.2  ad 
    346  1.2  ad static int
    347  1.2  ad pxg_ioctl(struct stic_info *si, u_long cmd, caddr_t data, int flag,
    348  1.2  ad 	  struct proc *p)
    349  1.2  ad {
    350  1.4  ad 	volatile u_int32_t *ptr;
    351  1.2  ad 	int rv;
    352  1.2  ad 
    353  1.2  ad 	if (cmd == STICIO_START860 || cmd == STICIO_RESET860) {
    354  1.2  ad 		if ((rv = suser(p->p_ucred, &p->p_acflag)) != 0)
    355  1.2  ad 			return (rv);
    356  1.4  ad 		ptr = (volatile u_int32_t *)si->si_slotbase;
    357  1.2  ad 		if (cmd == STICIO_START860)
    358  1.4  ad 			ptr[PXG_I860_START_OFFSET >> 2] = 1;
    359  1.2  ad 		else
    360  1.4  ad 			ptr[PXG_I860_RESET_OFFSET >> 2] = 0;
    361  1.4  ad 		tc_wmb();
    362  1.2  ad 		rv = 0;
    363  1.2  ad 	} else
    364  1.2  ad 		rv = ENOTTY;
    365  1.2  ad 
    366  1.2  ad 	return (rv);
    367  1.1  ad }
    368