Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: hyper.c,v 1.4 2025/05/27 18:44:31 tsutsui Exp $	*/
      2 /*	$OpenBSD: hyper.c,v 1.15 2006/04/14 21:05:43 miod Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 2005, Miodrag Vallat.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     20  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  * POSSIBILITY OF SUCH DAMAGE.
     28  *
     29  */
     30 /*-
     31  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
     32  * All rights reserved.
     33  *
     34  * This code is derived from software contributed to The NetBSD Foundation
     35  * by Jason R. Thorpe.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  *
     46  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     47  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     48  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     49  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     50  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     51  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     52  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     53  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     54  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     55  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     56  * POSSIBILITY OF SUCH DAMAGE.
     57  */
     58 
     59 /*
     60  * Copyright (c) 1991 University of Utah.
     61  * Copyright (c) 1990, 1993
     62  *	The Regents of the University of California.  All rights reserved.
     63  *
     64  * This code is derived from software contributed to Berkeley by
     65  * the Systems Programming Group of the University of Utah Computer
     66  * Science Department and Mark Davies of the Department of Computer
     67  * Science, Victoria University of Wellington, New Zealand.
     68  *
     69  * Redistribution and use in source and binary forms, with or without
     70  * modification, are permitted provided that the following conditions
     71  * are met:
     72  * 1. Redistributions of source code must retain the above copyright
     73  *    notice, this list of conditions and the following disclaimer.
     74  * 2. Redistributions in binary form must reproduce the above copyright
     75  *    notice, this list of conditions and the following disclaimer in the
     76  *    documentation and/or other materials provided with the distribution.
     77  * 3. Neither the name of the University nor the names of its contributors
     78  *    may be used to endorse or promote products derived from this software
     79  *    without specific prior written permission.
     80  *
     81  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     82  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     83  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     84  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     85  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     86  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     87  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     88  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     89  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     90  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     91  * SUCH DAMAGE.
     92  *
     93  * from: Utah $Hdr: grf_hy.c 1.2 93/08/13$
     94  *
     95  *	@(#)grf_hy.c	8.4 (Berkeley) 1/12/94
     96  */
     97 
     98 /*
     99  * Graphics routines for HYPERION frame buffer
    100  */
    101 
    102 #include <sys/param.h>
    103 #include <sys/systm.h>
    104 #include <sys/conf.h>
    105 #include <sys/device.h>
    106 #include <sys/ioctl.h>
    107 #include <sys/proc.h>
    108 #include <sys/bus.h>
    109 #include <sys/cpu.h>
    110 
    111 #include <machine/autoconf.h>
    112 
    113 #include <hp300/dev/dioreg.h>
    114 #include <hp300/dev/diovar.h>
    115 #include <hp300/dev/diodevs.h>
    116 #include <hp300/dev/intiovar.h>
    117 
    118 #include <dev/wscons/wsconsio.h>
    119 #include <dev/wscons/wsdisplayvar.h>
    120 #include <dev/rasops/rasops.h>
    121 
    122 #include <hp300/dev/diofbreg.h>
    123 #include <hp300/dev/diofbvar.h>
    124 #include <hp300/dev/hyperreg.h>
    125 
    126 struct	hyper_softc {
    127 	device_t		sc_dev;
    128 	struct diofb		*sc_fb;
    129 	struct diofb		sc_fb_store;
    130 	int			sc_scode;
    131 };
    132 
    133 static int	hyper_match(device_t, cfdata_t, void *);
    134 static void	hyper_attach(device_t, device_t, void *);
    135 
    136 CFATTACH_DECL_NEW(hyper, sizeof(struct hyper_softc),
    137     hyper_match, hyper_attach, NULL, NULL);
    138 
    139 static int	hyper_reset(struct diofb *, int, struct diofbreg *);
    140 
    141 static int	hyper_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    142 
    143 static struct wsdisplay_accessops hyper_accessops = {
    144 	.ioctl        = hyper_ioctl,
    145 	.mmap         = diofb_mmap,
    146 	.alloc_screen = diofb_alloc_screen,
    147 	.free_screen  = diofb_free_screen,
    148 	.show_screen  = diofb_show_screen,
    149 	.load_font    = NULL,
    150 };
    151 
    152 /*
    153  * Attachment glue
    154  */
    155 
    156 int
    157 hyper_match(device_t parent, cfdata_t cf, void *aux)
    158 {
    159 	struct dio_attach_args *da = aux;
    160 
    161 	if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER &&
    162 	    da->da_secid == DIO_DEVICE_SECID_HYPERION)
    163 		return 1;
    164 
    165 	return 0;
    166 }
    167 
    168 void
    169 hyper_attach(device_t parent, device_t self, void *aux)
    170 {
    171 	struct hyper_softc *sc = device_private(self);
    172 	struct dio_attach_args *da = aux;
    173 	bus_space_handle_t bsh;
    174 	struct diofbreg *fbr;
    175 
    176 	sc->sc_dev = self;
    177 	sc->sc_scode = da->da_scode;
    178 	if (sc->sc_scode == conscode) {
    179 		fbr = (struct diofbreg *)conaddr;	/* already mapped */
    180 		sc->sc_fb = &diofb_cn;
    181 	} else {
    182 		sc->sc_fb = &sc->sc_fb_store;
    183 		if (bus_space_map(da->da_bst, da->da_addr, da->da_size, 0,
    184 		    &bsh)) {
    185 			aprint_error(": can't map framebuffer\n");
    186 			return;
    187 		}
    188 		fbr = bus_space_vaddr(da->da_bst, bsh);
    189 		if (hyper_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
    190 			aprint_error(": can't reset framebuffer\n");
    191 			return;
    192 		}
    193 	}
    194 
    195 	diofb_end_attach(self, &hyper_accessops, sc->sc_fb,
    196 	    sc->sc_scode == conscode, NULL);
    197 }
    198 
    199 /*
    200  * Initialize hardware and display routines.
    201  */
    202 int
    203 hyper_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
    204 {
    205 	volatile struct hyboxfb *hy = (struct hyboxfb *)fbr;
    206 	int rc;
    207 
    208 	if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
    209 		return rc;
    210 
    211 	fb->bmv = diofb_mono_windowmove;
    212 
    213 	fb->ri.ri_depth = 1;	/* do not fake a 8bpp frame buffer */
    214 	diofb_fbsetup(fb);
    215 
    216 	/* enable display */
    217 	hy->nblank = DISP_VIDEO_ENABLE | DISP_SYNC_ENABLE;
    218 
    219 	return 0;
    220 }
    221 
    222 int
    223 hyper_ioctl(void *v, void *vs, u_long cmd, void *data, int flags, struct lwp *l)
    224 {
    225 	struct diofb *fb = v;
    226 	struct wsdisplay_fbinfo *wdf;
    227 
    228 	switch (cmd) {
    229 	case WSDISPLAYIO_GTYPE:
    230 		*(u_int *)data = WSDISPLAY_TYPE_HYPERION;
    231 		return 0;
    232 	case WSDISPLAYIO_SMODE:
    233 		fb->mapmode = *(u_int *)data;
    234 		return 0;
    235 	case WSDISPLAYIO_GINFO:
    236 		wdf = (void *)data;
    237 		wdf->width = fb->ri.ri_width;
    238 		wdf->height = fb->ri.ri_height;
    239 		wdf->depth = fb->ri.ri_depth;
    240 		wdf->cmsize = 0;
    241 		return 0;
    242 	case WSDISPLAYIO_LINEBYTES:
    243 		*(u_int *)data = fb->ri.ri_stride;
    244 		return 0;
    245 	case WSDISPLAYIO_GVIDEO:
    246 	case WSDISPLAYIO_SVIDEO:
    247 		return EPASSTHROUGH;
    248 	case WSDISPLAYIO_GETCMAP:
    249 	case WSDISPLAYIO_PUTCMAP:
    250 		return EPASSTHROUGH;
    251 	}
    252 
    253 	return EPASSTHROUGH;
    254 }
    255 
    256 /*
    257  * Hyperion console support
    258  */
    259 
    260 int
    261 hypercnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
    262 {
    263 	bus_space_handle_t bsh;
    264 	void *va;
    265 	struct diofbreg *fbr;
    266 	struct diofb *fb = &diofb_cn;
    267 	int size;
    268 
    269 	if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
    270 		return 1;
    271 	va = bus_space_vaddr(bst, bsh);
    272 	fbr = va;
    273 
    274 	if (badaddr(va) ||
    275 	    (fbr->id != GRFHWID) || (fbr->fbid != GID_HYPERION)) {
    276 		bus_space_unmap(bst, bsh, PAGE_SIZE);
    277 		return 1;
    278 	}
    279 
    280 	size = DIO_SIZE(scode, va);
    281 
    282 	bus_space_unmap(bst, bsh, PAGE_SIZE);
    283 	if (bus_space_map(bst, addr, size, 0, &bsh))
    284 		return 1;
    285 	va = bus_space_vaddr(bst, bsh);
    286 
    287 	/*
    288 	 * Initialize the framebuffer hardware.
    289 	 */
    290 	conscode = scode;
    291 	conaddr = va;
    292 	hyper_reset(fb, conscode, (struct diofbreg *)conaddr);
    293 
    294 	/*
    295 	 * Initialize the terminal emulator.
    296 	 */
    297 	diofb_cnattach(fb);
    298 	return 0;
    299 }
    300