Home | History | Annotate | Line # | Download | only in dev
bw2.c revision 1.34.30.1
      1  1.34.30.1      yamt /*	$NetBSD: bw2.c,v 1.34.30.1 2014/05/22 11:40:10 yamt 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.25       agc  * 3. Neither the name of the University nor the names of its contributors
     25        1.1       gwr  *    may be used to endorse or promote products derived from this software
     26        1.1       gwr  *    without specific prior written permission.
     27        1.1       gwr  *
     28        1.1       gwr  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29        1.1       gwr  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30        1.1       gwr  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31        1.1       gwr  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32        1.1       gwr  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33        1.1       gwr  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34        1.1       gwr  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35        1.1       gwr  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36        1.1       gwr  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37        1.1       gwr  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38        1.1       gwr  * SUCH DAMAGE.
     39        1.1       gwr  *
     40        1.1       gwr  *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
     41        1.1       gwr  */
     42        1.1       gwr 
     43        1.1       gwr /*
     44        1.1       gwr  * black&white display (bw2) driver.
     45        1.1       gwr  *
     46        1.1       gwr  * Does not handle interrupts, even though they can occur.
     47        1.1       gwr  */
     48       1.24     lukem 
     49       1.24     lukem #include <sys/cdefs.h>
     50  1.34.30.1      yamt __KERNEL_RCSID(0, "$NetBSD: bw2.c,v 1.34.30.1 2014/05/22 11:40:10 yamt Exp $");
     51        1.1       gwr 
     52        1.1       gwr #include <sys/param.h>
     53        1.9       gwr #include <sys/systm.h>
     54        1.9       gwr #include <sys/conf.h>
     55        1.1       gwr #include <sys/device.h>
     56        1.1       gwr #include <sys/ioctl.h>
     57        1.1       gwr #include <sys/malloc.h>
     58        1.1       gwr #include <sys/mman.h>
     59        1.9       gwr #include <sys/proc.h>
     60        1.1       gwr #include <sys/tty.h>
     61        1.1       gwr 
     62       1.16       mrg #include <uvm/uvm_extern.h>
     63        1.1       gwr 
     64        1.9       gwr #include <machine/autoconf.h>
     65        1.2       gwr #include <machine/cpu.h>
     66       1.17   thorpej #include <dev/sun/fbio.h>
     67        1.9       gwr #include <machine/idprom.h>
     68        1.1       gwr #include <machine/pmap.h>
     69        1.1       gwr 
     70       1.14       gwr #include <sun3/dev/fbvar.h>
     71       1.14       gwr #include <sun3/dev/bw2reg.h>
     72       1.14       gwr #include <sun3/dev/p4reg.h>
     73        1.1       gwr 
     74       1.34   tsutsui #include "ioconf.h"
     75       1.34   tsutsui 
     76        1.1       gwr /* per-display variables */
     77        1.1       gwr struct bw2_softc {
     78       1.34   tsutsui 	device_t sc_dev;		/* base device */
     79        1.1       gwr 	struct	fbdevice sc_fb;		/* frame buffer device */
     80        1.1       gwr 	int 	sc_phys;		/* display RAM (phys addr) */
     81       1.13       gwr 	/* If using overlay plane of something, it is... */
     82       1.13       gwr 	int	sc_ovtype;		/* ... this type. */
     83       1.13       gwr 	int sc_video_on;
     84        1.1       gwr };
     85        1.1       gwr 
     86        1.1       gwr /* autoconfiguration driver */
     87       1.34   tsutsui static int	bw2match(device_t, cfdata_t, void *);
     88       1.34   tsutsui static void	bw2attach(device_t, device_t, void *);
     89        1.1       gwr 
     90       1.34   tsutsui CFATTACH_DECL_NEW(bwtwo, sizeof(struct bw2_softc),
     91       1.22   thorpej     bw2match, bw2attach, NULL, NULL);
     92        1.6   thorpej 
     93       1.19   gehenna dev_type_open(bw2open);
     94       1.19   gehenna dev_type_ioctl(bw2ioctl);
     95       1.19   gehenna dev_type_mmap(bw2mmap);
     96       1.19   gehenna 
     97       1.19   gehenna const struct cdevsw bwtwo_cdevsw = {
     98  1.34.30.1      yamt 	.d_open = bw2open,
     99  1.34.30.1      yamt 	.d_close = nullclose,
    100  1.34.30.1      yamt 	.d_read = noread,
    101  1.34.30.1      yamt 	.d_write = nowrite,
    102  1.34.30.1      yamt 	.d_ioctl = bw2ioctl,
    103  1.34.30.1      yamt 	.d_stop = nostop,
    104  1.34.30.1      yamt 	.d_tty = notty,
    105  1.34.30.1      yamt 	.d_poll = nopoll,
    106  1.34.30.1      yamt 	.d_mmap = bw2mmap,
    107  1.34.30.1      yamt 	.d_kqfilter = nokqfilter,
    108  1.34.30.1      yamt 	.d_flag = 0
    109       1.19   gehenna };
    110       1.19   gehenna 
    111        1.1       gwr /* XXX we do not handle frame buffer interrupts */
    112        1.1       gwr 
    113       1.26       chs static int bw2gvideo(struct fbdevice *, void *);
    114       1.26       chs static int bw2svideo(struct fbdevice *, void *);
    115        1.1       gwr 
    116        1.1       gwr static struct fbdriver bw2fbdriver = {
    117       1.23  jdolecek 	bw2open, nullclose, bw2mmap, nokqfilter,
    118        1.9       gwr 	fb_noioctl,
    119        1.1       gwr 	bw2gvideo, bw2svideo,
    120        1.9       gwr 	fb_noioctl, fb_noioctl, };
    121        1.1       gwr 
    122       1.26       chs static int
    123       1.34   tsutsui bw2match(device_t parent, cfdata_t cf, void *args)
    124        1.1       gwr {
    125        1.1       gwr 	struct confargs *ca = args;
    126       1.14       gwr 	int mid, p4id, peekval;
    127       1.14       gwr 	void *p4reg;
    128       1.14       gwr 
    129       1.14       gwr 	/* No default address support. */
    130       1.14       gwr 	if (ca->ca_paddr == -1)
    131       1.34   tsutsui 		return 0;
    132        1.1       gwr 
    133        1.1       gwr 	/*
    134       1.14       gwr 	 * Slight hack here:  The low four bits of the
    135       1.14       gwr 	 * config flags, if set, restrict the match to
    136       1.14       gwr 	 * that machine "implementation" only.
    137        1.1       gwr 	 */
    138       1.14       gwr 	mid = cf->cf_flags & IDM_IMPL_MASK;
    139       1.34   tsutsui 	if (mid != 0 && (mid != (cpu_machine_id & IDM_IMPL_MASK)))
    140       1.34   tsutsui 		return 0;
    141        1.1       gwr 
    142       1.14       gwr 	/*
    143       1.14       gwr 	 * Make sure something is there, and if so,
    144       1.14       gwr 	 * see if it looks like a P4 register.
    145       1.14       gwr 	 */
    146       1.14       gwr 	p4reg = bus_tmapin(ca->ca_bustype, ca->ca_paddr);
    147       1.14       gwr 	peekval = peek_long(p4reg);
    148       1.34   tsutsui 	p4id = (peekval == -1) ? P4_NOTFOUND : fb_pfour_id(p4reg);
    149       1.14       gwr 	bus_tmapout(p4reg);
    150       1.14       gwr 	if (peekval == -1)
    151       1.34   tsutsui 		return 0;
    152       1.14       gwr 
    153       1.14       gwr 	/*
    154       1.14       gwr 	 * The config flag 0x40 if set means we should match
    155       1.14       gwr 	 * only on a CG? overlay plane.  We can use only the
    156       1.14       gwr 	 * CG4 and CG8, which both have a P4 register.
    157       1.14       gwr 	 */
    158       1.14       gwr 	if (cf->cf_flags & 0x40) {
    159       1.14       gwr 		switch (p4id) {
    160       1.14       gwr 		case P4_ID_COLOR8P1:
    161       1.14       gwr 		case P4_ID_COLOR24:
    162       1.34   tsutsui 			return 1;
    163       1.14       gwr 		case P4_NOTFOUND:
    164       1.14       gwr 		default:
    165       1.34   tsutsui 			return 0;
    166       1.14       gwr 		}
    167       1.14       gwr 	}
    168       1.14       gwr 
    169       1.14       gwr 	/*
    170       1.14       gwr 	 * OK, we are expecting a plain old BW2, and
    171       1.14       gwr 	 * there may or may not be a P4 register.
    172       1.14       gwr 	 */
    173       1.14       gwr 	switch (p4id) {
    174       1.14       gwr 	case P4_ID_BW:
    175       1.14       gwr 	case P4_NOTFOUND:
    176       1.34   tsutsui 		return 1;
    177       1.14       gwr 	default:
    178       1.14       gwr #ifdef	DEBUG
    179       1.34   tsutsui 		aprint_debug("bwtwo at 0x%lx match p4id=0x%x fails\n",
    180       1.34   tsutsui 		    ca->ca_paddr, p4id & 0xFF);
    181       1.13       gwr #endif
    182       1.18   thorpej 		break;
    183        1.1       gwr 	}
    184        1.1       gwr 
    185       1.34   tsutsui 	return 0;
    186        1.1       gwr }
    187        1.1       gwr 
    188        1.1       gwr /*
    189        1.1       gwr  * Attach a display.  We need to notice if it is the console, too.
    190        1.1       gwr  */
    191       1.26       chs static void
    192       1.34   tsutsui bw2attach(device_t parent, device_t self, void *args)
    193        1.1       gwr {
    194       1.33   tsutsui 	struct bw2_softc *sc = device_private(self);
    195        1.1       gwr 	struct fbdevice *fb = &sc->sc_fb;
    196        1.1       gwr 	struct confargs *ca = args;
    197        1.1       gwr 	struct fbtype *fbt;
    198       1.14       gwr 	void *p4reg;
    199       1.14       gwr 	int p4id, tmp;
    200       1.14       gwr 	int pixeloffset;		/* offset to framebuffer */
    201        1.1       gwr 
    202       1.34   tsutsui 	sc->sc_dev = self;
    203       1.34   tsutsui 
    204        1.1       gwr 	fbt = &fb->fb_fbtype;
    205        1.1       gwr 	fbt->fb_type = FBTYPE_SUN2BW;
    206       1.14       gwr 	fbt->fb_width = 1152;	/* default - see below */
    207       1.14       gwr 	fbt->fb_height = 900;	/* default - see below */
    208        1.1       gwr 	fbt->fb_depth = 1;
    209        1.1       gwr 	fbt->fb_cmsize = 0;
    210       1.13       gwr 	fbt->fb_size = BW2_FBSIZE;	/* default - see below */
    211       1.13       gwr 	fb->fb_driver = &bw2fbdriver;
    212       1.13       gwr 	fb->fb_private = sc;
    213       1.34   tsutsui 	fb->fb_name  = device_xname(self);
    214       1.34   tsutsui 	fb->fb_flags = device_cfdata(self)->cf_flags;
    215       1.14       gwr 
    216       1.14       gwr 	/* Set up default pixel offset.  May be changed below. */
    217       1.14       gwr 	pixeloffset = 0;
    218       1.14       gwr 
    219       1.14       gwr 	/* Does it have a P4 register? */
    220       1.14       gwr 	p4reg = bus_mapin(ca->ca_bustype, ca->ca_paddr, 4);
    221       1.14       gwr 	p4id = fb_pfour_id(p4reg);
    222       1.14       gwr 	if (p4id != P4_NOTFOUND)
    223       1.14       gwr 		fb->fb_pfour = p4reg;
    224       1.14       gwr 	else
    225       1.14       gwr 		bus_mapout(p4reg, 4);
    226       1.14       gwr 
    227       1.14       gwr 	switch (p4id) {
    228       1.14       gwr 	case P4_NOTFOUND:
    229       1.14       gwr 		pixeloffset = 0;
    230       1.14       gwr 		break;
    231        1.1       gwr 
    232       1.14       gwr 	case P4_ID_BW:
    233       1.14       gwr 		pixeloffset = P4_BW_OFF;
    234       1.10       gwr 		break;
    235       1.10       gwr 
    236       1.14       gwr 	default:
    237       1.34   tsutsui 		aprint_error("%s: bad p4id=0x%x\n", fb->fb_name, p4id);
    238       1.14       gwr 		/* Must be some kinda color... */
    239       1.34   tsutsui 		/* FALLTHROUGH */
    240       1.14       gwr 	case P4_ID_COLOR8P1:
    241       1.14       gwr 	case P4_ID_COLOR24:
    242       1.14       gwr 		sc->sc_ovtype = p4id;
    243       1.14       gwr 		pixeloffset = P4_COLOR_OFF_OVERLAY;
    244       1.10       gwr 		break;
    245        1.1       gwr 	}
    246       1.14       gwr 	sc->sc_phys = ca->ca_paddr + pixeloffset;
    247       1.14       gwr 
    248       1.14       gwr 	/*
    249       1.14       gwr 	 * Determine width and height as follows:
    250       1.14       gwr 	 * If it has a P4 register, use that;
    251       1.14       gwr 	 * else if unit==0, use the EEPROM size,
    252       1.14       gwr 	 * else make our best guess.
    253       1.14       gwr 	 */
    254       1.14       gwr 	if (fb->fb_pfour)
    255       1.14       gwr 		fb_pfour_setsize(fb);
    256       1.29   thorpej 	/* XXX device_unit() abuse */
    257       1.34   tsutsui 	else if (device_unit(self) == 0)
    258       1.14       gwr 		fb_eeprom_setsize(fb);
    259       1.14       gwr 	else {
    260       1.14       gwr 		/* Guess based on machine ID. */
    261       1.14       gwr 		switch (cpu_machine_id) {
    262       1.14       gwr #ifdef	_SUN3_
    263       1.27   thorpej 		case ID_SUN3_60:
    264       1.14       gwr 			/*
    265       1.14       gwr 			 * Only the model 60 can have hi-res.
    266       1.14       gwr 			 * Look at the "resolution" jumper.
    267       1.14       gwr 			 */
    268       1.14       gwr 			tmp = bus_peek(BUS_OBMEM, BW2_CR_PADDR, 1);
    269       1.14       gwr 			if ((tmp != -1) && (tmp & 0x80) == 0)
    270       1.14       gwr 				goto high_res;
    271       1.14       gwr 			break;
    272       1.14       gwr 
    273       1.27   thorpej 		case ID_SUN3_260:
    274       1.14       gwr 			/* The Sun3/260 is ALWAYS high-resolution! */
    275       1.14       gwr 			/* fall through */
    276       1.14       gwr 		high_res:
    277       1.14       gwr 			fbt->fb_width = 1600;
    278       1.14       gwr 			fbt->fb_height = 1280;
    279       1.14       gwr 			fbt->fb_size = BW2_FBSIZE_HIRES;
    280       1.14       gwr 			break;
    281       1.13       gwr #endif	/* SUN3 */
    282        1.1       gwr 
    283       1.14       gwr 		default:
    284       1.14       gwr 			/* Leave the defaults set above. */
    285       1.14       gwr 			break;
    286       1.14       gwr 		}
    287       1.14       gwr 	}
    288       1.34   tsutsui 	aprint_normal(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
    289       1.14       gwr 
    290       1.14       gwr 	/* Make sure video is on. */
    291       1.14       gwr 	tmp = 1;
    292       1.14       gwr 	bw2svideo(fb, &tmp);
    293       1.14       gwr 
    294       1.14       gwr 	/* Let /dev/fb know we are here. */
    295        1.2       gwr 	fb_attach(fb, 1);
    296        1.1       gwr }
    297        1.1       gwr 
    298       1.26       chs int
    299       1.28  christos bw2open(dev_t dev, int flags, int mode, struct lwp *l)
    300        1.1       gwr {
    301       1.33   tsutsui 	struct bw2_softc *sc;
    302        1.1       gwr 	int unit = minor(dev);
    303        1.1       gwr 
    304       1.33   tsutsui 	sc = device_lookup_private(&bwtwo_cd, unit);
    305       1.33   tsutsui 	if (sc == NULL)
    306       1.34   tsutsui 		return ENXIO;
    307       1.34   tsutsui 	return 0;
    308        1.1       gwr }
    309        1.1       gwr 
    310       1.26       chs int
    311       1.31  christos bw2ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
    312        1.1       gwr {
    313       1.33   tsutsui 	struct bw2_softc *sc = device_lookup_private(&bwtwo_cd, minor(dev));
    314        1.1       gwr 
    315       1.34   tsutsui 	return fbioctlfb(&sc->sc_fb, cmd, data);
    316        1.1       gwr }
    317        1.1       gwr 
    318        1.1       gwr /*
    319        1.1       gwr  * Return the address that would map the given device at the given
    320        1.1       gwr  * offset, allowing for the given protection, or return -1 for error.
    321        1.1       gwr  */
    322       1.26       chs paddr_t
    323       1.26       chs bw2mmap(dev_t dev, off_t off, int prot)
    324        1.1       gwr {
    325       1.33   tsutsui 	struct bw2_softc *sc = device_lookup_private(&bwtwo_cd, minor(dev));
    326       1.14       gwr 	int size = sc->sc_fb.fb_fbtype.fb_size;
    327        1.1       gwr 
    328        1.1       gwr 	if (off & PGOFSET)
    329       1.34   tsutsui 		panic("%s: bad offset", __func__);
    330       1.14       gwr 
    331       1.14       gwr 	if ((off < 0) || (off >= size))
    332       1.34   tsutsui 		return -1;
    333       1.14       gwr 
    334        1.1       gwr 	/*
    335        1.1       gwr 	 * I turned on PMAP_NC here to disable the cache as I was
    336       1.14       gwr 	 * getting horribly broken behaviour without it.
    337        1.1       gwr 	 */
    338       1.34   tsutsui 	return (sc->sc_phys + off) | PMAP_NC;
    339        1.1       gwr }
    340        1.1       gwr 
    341        1.1       gwr /* FBIOGVIDEO: */
    342       1.26       chs static int
    343       1.26       chs bw2gvideo(struct fbdevice *fb, void *data)
    344        1.1       gwr {
    345       1.13       gwr 	struct bw2_softc *sc = fb->fb_private;
    346        1.9       gwr 	int *on = data;
    347        1.1       gwr 
    348       1.13       gwr 	*on = sc->sc_video_on;
    349       1.34   tsutsui 	return 0;
    350        1.1       gwr }
    351        1.1       gwr 
    352       1.14       gwr /* FBIOSVIDEO: */
    353       1.26       chs static int
    354       1.26       chs bw2svideo(struct fbdevice *fb, void *data)
    355        1.1       gwr {
    356       1.13       gwr 	struct bw2_softc *sc = fb->fb_private;
    357        1.9       gwr 	int *on = data;
    358        1.1       gwr 
    359       1.13       gwr 	if (sc->sc_video_on == *on)
    360       1.34   tsutsui 		return 0;
    361       1.13       gwr 	sc->sc_video_on = *on;
    362        1.1       gwr 
    363       1.14       gwr 	if (fb->fb_pfour)
    364       1.14       gwr 		fb_pfour_set_video(fb, sc->sc_video_on);
    365       1.14       gwr 	else
    366       1.14       gwr 		enable_video(sc->sc_video_on);
    367        1.1       gwr 
    368       1.34   tsutsui 	return 0;
    369        1.1       gwr }
    370