Home | History | Annotate | Line # | Download | only in dev
bw2.c revision 1.12.2.1
      1  1.12.2.1       gwr /*	$NetBSD: bw2.c,v 1.12.2.1 1998/01/27 19:16:35 gwr Exp $	*/
      2       1.1       gwr 
      3       1.1       gwr /*
      4       1.1       gwr  * Copyright (c) 1992, 1993
      5       1.1       gwr  *	The Regents of the University of California.  All rights reserved.
      6       1.1       gwr  *
      7       1.1       gwr  * This software was developed by the Computer Systems Engineering group
      8       1.1       gwr  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9       1.1       gwr  * contributed to Berkeley.
     10       1.1       gwr  *
     11       1.1       gwr  * All advertising materials mentioning features or use of this software
     12       1.1       gwr  * must display the following acknowledgement:
     13       1.1       gwr  *	This product includes software developed by the University of
     14       1.1       gwr  *	California, Lawrence Berkeley Laboratory.
     15       1.1       gwr  *
     16       1.1       gwr  * Redistribution and use in source and binary forms, with or without
     17       1.1       gwr  * modification, are permitted provided that the following conditions
     18       1.1       gwr  * are met:
     19       1.1       gwr  * 1. Redistributions of source code must retain the above copyright
     20       1.1       gwr  *    notice, this list of conditions and the following disclaimer.
     21       1.1       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     22       1.1       gwr  *    notice, this list of conditions and the following disclaimer in the
     23       1.1       gwr  *    documentation and/or other materials provided with the distribution.
     24       1.1       gwr  * 3. All advertising materials mentioning features or use of this software
     25       1.1       gwr  *    must display the following acknowledgement:
     26       1.1       gwr  *	This product includes software developed by the University of
     27       1.1       gwr  *	California, Berkeley and its contributors.
     28       1.1       gwr  * 4. Neither the name of the University nor the names of its contributors
     29       1.1       gwr  *    may be used to endorse or promote products derived from this software
     30       1.1       gwr  *    without specific prior written permission.
     31       1.1       gwr  *
     32       1.1       gwr  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33       1.1       gwr  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34       1.1       gwr  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35       1.1       gwr  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36       1.1       gwr  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37       1.1       gwr  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38       1.1       gwr  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39       1.1       gwr  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40       1.1       gwr  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41       1.1       gwr  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42       1.1       gwr  * SUCH DAMAGE.
     43       1.1       gwr  *
     44       1.1       gwr  *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
     45       1.1       gwr  */
     46       1.1       gwr 
     47       1.1       gwr /*
     48       1.1       gwr  * black&white display (bw2) driver.
     49       1.1       gwr  *
     50       1.1       gwr  * Does not handle interrupts, even though they can occur.
     51       1.1       gwr  */
     52       1.1       gwr 
     53       1.1       gwr #include <sys/param.h>
     54       1.9       gwr #include <sys/systm.h>
     55       1.9       gwr #include <sys/conf.h>
     56       1.1       gwr #include <sys/device.h>
     57       1.1       gwr #include <sys/ioctl.h>
     58       1.1       gwr #include <sys/malloc.h>
     59       1.1       gwr #include <sys/mman.h>
     60       1.9       gwr #include <sys/proc.h>
     61       1.1       gwr #include <sys/tty.h>
     62       1.1       gwr 
     63       1.1       gwr #include <vm/vm.h>
     64       1.1       gwr 
     65       1.9       gwr #include <machine/autoconf.h>
     66       1.2       gwr #include <machine/cpu.h>
     67       1.1       gwr #include <machine/fbio.h>
     68       1.9       gwr #include <machine/idprom.h>
     69       1.1       gwr #include <machine/pmap.h>
     70       1.1       gwr 
     71  1.12.2.1       gwr #include <sun3/sun3/machdep.h>
     72  1.12.2.1       gwr 
     73       1.1       gwr #include "fbvar.h"
     74       1.1       gwr #include "bw2reg.h"
     75       1.1       gwr 
     76       1.9       gwr cdev_decl(bw2);
     77       1.1       gwr 
     78       1.1       gwr /* per-display variables */
     79       1.1       gwr struct bw2_softc {
     80       1.1       gwr 	struct	device sc_dev;		/* base device */
     81       1.1       gwr 	struct	fbdevice sc_fb;		/* frame buffer device */
     82       1.1       gwr 	int 	sc_phys;		/* display RAM (phys addr) */
     83  1.12.2.1       gwr 	int 	sc_pixeloffset;		/* offset to framebuffer */
     84  1.12.2.1       gwr 	/* If using overlay plane of something, it is... */
     85  1.12.2.1       gwr 	int	sc_ovtype;		/* ... this type. */
     86  1.12.2.1       gwr 	int sc_video_on;
     87       1.1       gwr };
     88       1.1       gwr 
     89       1.1       gwr /* autoconfiguration driver */
     90       1.1       gwr static void	bw2attach __P((struct device *, struct device *, void *));
     91       1.9       gwr static int	bw2match __P((struct device *, struct cfdata *, void *));
     92       1.1       gwr 
     93       1.6   thorpej struct cfattach bwtwo_ca = {
     94       1.6   thorpej 	sizeof(struct bw2_softc), bw2match, bw2attach
     95       1.6   thorpej };
     96       1.6   thorpej 
     97      1.12   thorpej extern struct cfdriver bwtwo_cd;
     98       1.1       gwr 
     99       1.1       gwr /* XXX we do not handle frame buffer interrupts */
    100       1.1       gwr 
    101       1.9       gwr static int  bw2gvideo __P((struct fbdevice *, void *));
    102       1.9       gwr static int	bw2svideo __P((struct fbdevice *, void *));
    103       1.1       gwr 
    104       1.1       gwr static struct fbdriver bw2fbdriver = {
    105       1.4   mycroft 	bw2open, bw2close, bw2mmap,
    106       1.9       gwr 	fb_noioctl,
    107       1.1       gwr 	bw2gvideo, bw2svideo,
    108       1.9       gwr 	fb_noioctl, fb_noioctl, };
    109       1.1       gwr 
    110       1.1       gwr static int
    111       1.9       gwr bw2match(parent, cf, args)
    112       1.1       gwr 	struct device *parent;
    113       1.9       gwr 	struct cfdata *cf;
    114       1.9       gwr 	void *args;
    115       1.1       gwr {
    116       1.1       gwr 	struct confargs *ca = args;
    117       1.1       gwr 	int x;
    118       1.1       gwr 
    119       1.5       gwr #if 0	/* XXX - Assume only one is in use anyway... */
    120       1.1       gwr 	/*
    121       1.1       gwr 	 * This driver only supports one unit because the
    122       1.1       gwr 	 * system enable register is used for blanking.
    123       1.1       gwr 	 */
    124       1.1       gwr 	if (cf->cf_unit != 0)
    125       1.1       gwr 		return (0);
    126       1.5       gwr #endif
    127       1.1       gwr 
    128       1.1       gwr 	if (ca->ca_paddr == -1) {
    129  1.12.2.1       gwr #ifdef	_SUN3X_
    130  1.12.2.1       gwr 		/* Demand an address locator on 3X. */
    131  1.12.2.1       gwr 		return (0);
    132  1.12.2.1       gwr #else
    133       1.1       gwr 		if (cpu_machine_id == SUN3_MACH_50)
    134       1.1       gwr 			ca->ca_paddr = BW2_50_PADDR;
    135       1.1       gwr 		else
    136       1.1       gwr 			ca->ca_paddr = BW2_FB_PADDR;
    137  1.12.2.1       gwr #endif
    138       1.1       gwr 	}
    139       1.1       gwr 
    140       1.1       gwr 	/* The peek returns -1 on bus error. */
    141       1.1       gwr 	x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
    142       1.1       gwr 	return (x != -1);
    143       1.1       gwr }
    144       1.1       gwr 
    145       1.1       gwr /*
    146       1.1       gwr  * Attach a display.  We need to notice if it is the console, too.
    147       1.1       gwr  */
    148       1.1       gwr static void
    149       1.1       gwr bw2attach(parent, self, args)
    150       1.1       gwr 	struct device *parent, *self;
    151       1.1       gwr 	void *args;
    152       1.1       gwr {
    153       1.1       gwr 	struct bw2_softc *sc = (struct bw2_softc *)self;
    154       1.1       gwr 	struct fbdevice *fb = &sc->sc_fb;
    155       1.1       gwr 	struct confargs *ca = args;
    156       1.1       gwr 	struct fbtype *fbt;
    157      1.10       gwr 	int tmp;
    158       1.1       gwr 
    159       1.1       gwr 	sc->sc_phys = ca->ca_paddr;
    160       1.1       gwr 
    161       1.1       gwr 	fbt = &fb->fb_fbtype;
    162       1.1       gwr 	fbt->fb_type = FBTYPE_SUN2BW;
    163  1.12.2.1       gwr 	fbt->fb_width = 1152;		/* default - see below */
    164  1.12.2.1       gwr 	fbt->fb_height = 900;		/* default - see below */
    165       1.1       gwr 	fbt->fb_depth = 1;
    166       1.1       gwr 	fbt->fb_cmsize = 0;
    167  1.12.2.1       gwr 	fbt->fb_size = BW2_FBSIZE;	/* default - see below */
    168  1.12.2.1       gwr 	fb->fb_driver = &bw2fbdriver;
    169  1.12.2.1       gwr 	fb->fb_private = sc;
    170  1.12.2.1       gwr 	fb->fb_name = sc->sc_dev.dv_xname;
    171       1.1       gwr 
    172  1.12.2.1       gwr #ifdef	_SUN3_
    173      1.10       gwr 	switch (cpu_machine_id) {
    174      1.10       gwr 	case SUN3_MACH_60:
    175      1.10       gwr 		/*
    176      1.10       gwr 		 * Only the model 60 can have hi-res.
    177      1.10       gwr 		 * XXX - Use PROM screen size values?
    178      1.10       gwr 		 */
    179       1.1       gwr 	    tmp = bus_peek(BUS_OBMEM, BW2_CR_PADDR, 1);
    180      1.10       gwr 		if ((tmp != -1) && (tmp & 0x80) == 0)
    181      1.10       gwr 			goto high_res;
    182      1.10       gwr 		break;
    183      1.10       gwr 
    184      1.10       gwr 	case SUN3_MACH_260:
    185      1.10       gwr 		/* The Sun3/260 is ALWAYS high-resolution! */
    186      1.10       gwr 	high_res:
    187      1.10       gwr 		fbt->fb_width = 1600;
    188      1.10       gwr 		fbt->fb_height = 1280;
    189      1.10       gwr 		fbt->fb_size = BW2_FBSIZE_HIRES;
    190      1.10       gwr 		break;
    191       1.1       gwr 	}
    192  1.12.2.1       gwr #endif	/* SUN3 */
    193       1.1       gwr 
    194       1.8  christos 	printf(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
    195       1.2       gwr 	fb_attach(fb, 1);
    196       1.1       gwr }
    197       1.1       gwr 
    198       1.1       gwr int
    199       1.1       gwr bw2open(dev, flags, mode, p)
    200       1.1       gwr 	dev_t dev;
    201       1.1       gwr 	int flags, mode;
    202       1.1       gwr 	struct proc *p;
    203       1.1       gwr {
    204       1.1       gwr 	int unit = minor(dev);
    205       1.1       gwr 
    206       1.6   thorpej 	if (unit >= bwtwo_cd.cd_ndevs || bwtwo_cd.cd_devs[unit] == NULL)
    207       1.1       gwr 		return (ENXIO);
    208       1.1       gwr 	return (0);
    209       1.1       gwr }
    210       1.1       gwr 
    211       1.1       gwr int
    212       1.1       gwr bw2close(dev, flags, mode, p)
    213       1.1       gwr 	dev_t dev;
    214       1.1       gwr 	int flags, mode;
    215       1.1       gwr 	struct proc *p;
    216       1.1       gwr {
    217       1.1       gwr 
    218       1.1       gwr 	return (0);
    219       1.1       gwr }
    220       1.1       gwr 
    221       1.1       gwr int
    222       1.1       gwr bw2ioctl(dev, cmd, data, flags, p)
    223       1.1       gwr 	dev_t dev;
    224       1.1       gwr 	u_long cmd;
    225       1.1       gwr 	caddr_t data;
    226       1.1       gwr 	int flags;
    227       1.1       gwr 	struct proc *p;
    228       1.1       gwr {
    229       1.6   thorpej 	struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
    230       1.1       gwr 
    231       1.1       gwr 	return (fbioctlfb(&sc->sc_fb, cmd, data));
    232       1.1       gwr }
    233       1.1       gwr 
    234       1.1       gwr /*
    235       1.1       gwr  * Return the address that would map the given device at the given
    236       1.1       gwr  * offset, allowing for the given protection, or return -1 for error.
    237       1.1       gwr  */
    238       1.1       gwr int
    239       1.3   mycroft bw2mmap(dev, off, prot)
    240       1.1       gwr 	dev_t dev;
    241       1.1       gwr 	int off, prot;
    242       1.1       gwr {
    243       1.6   thorpej 	struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
    244       1.1       gwr 
    245       1.1       gwr 	if (off & PGOFSET)
    246       1.1       gwr 		return (-1);
    247       1.1       gwr 	if ((unsigned)off >= sc->sc_fb.fb_fbtype.fb_size)
    248       1.1       gwr 		return (-1);
    249       1.1       gwr 	/*
    250       1.1       gwr 	 * I turned on PMAP_NC here to disable the cache as I was
    251       1.1       gwr 	 * getting horribly broken behaviour with it on.
    252       1.1       gwr 	 */
    253       1.1       gwr 	return ((sc->sc_phys + off) | PMAP_NC);
    254       1.1       gwr }
    255       1.1       gwr 
    256       1.1       gwr /* FBIOGVIDEO: */
    257       1.9       gwr static int bw2gvideo(fb, data)
    258       1.1       gwr 	struct fbdevice *fb;
    259       1.9       gwr 	void *data;
    260       1.1       gwr {
    261  1.12.2.1       gwr 	struct bw2_softc *sc = fb->fb_private;
    262       1.9       gwr 	int *on = data;
    263       1.1       gwr 
    264  1.12.2.1       gwr 	*on = sc->sc_video_on;
    265       1.1       gwr 	return (0);
    266       1.1       gwr }
    267       1.1       gwr 
    268       1.1       gwr /* FBIOSVIDEO */
    269       1.9       gwr static int bw2svideo(fb, data)
    270       1.1       gwr 	struct fbdevice *fb;
    271       1.9       gwr 	void *data;
    272       1.1       gwr {
    273  1.12.2.1       gwr 	struct bw2_softc *sc = fb->fb_private;
    274       1.9       gwr 	int *on = data;
    275       1.1       gwr 
    276  1.12.2.1       gwr 	if (sc->sc_video_on == *on)
    277  1.12.2.1       gwr 		return (0);
    278  1.12.2.1       gwr 	sc->sc_video_on = *on;
    279       1.1       gwr 
    280  1.12.2.1       gwr 	/* XXX: P4 support... */
    281  1.12.2.1       gwr 	enable_video(sc->sc_video_on);
    282       1.1       gwr 
    283       1.1       gwr 	return(0);
    284       1.1       gwr }
    285