/* $NetBSD: smg.c,v 1.67 2024/02/03 16:35:10 tsutsui Exp $ */
/* $OpenBSD: smg.c,v 1.28 2014/12/23 21:39:12 miod Exp $ */
/*
* Copyright (c) 2006, Miodrag Vallat
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Tohru Nishimura.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1998 Ludd, University of Lule}, Sweden.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
* Copyright (c) 1991 University of Utah.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department and Mark Davies of the Department of Computer
* Science, Victoria University of Wellington, New Zealand.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah $Hdr: grf_hy.c 1.2 93/08/13$
*
* @(#)grf_hy.c 8.4 (Berkeley) 1/12/94
*/
static int
smg_match(device_t parent, cfdata_t cf, void *aux)
{
struct vsbus_attach_args *va = aux;
volatile short *curcmd;
volatile short *cfgtst;
short tmp, tmp2;
switch (vax_boardtype) {
default:
return 0;
case VAX_BTYP_410:
case VAX_BTYP_420:
case VAX_BTYP_43:
if (va->va_paddr != KA420_CUR_BASE)
return 0;
/* not present on microvaxes */
if ((vax_confdata & KA420_CFG_MULTU) != 0)
return 0;
/*
* If the color option board is present, do not attach
* unless we are explicitely asked to via device flags.
*/
if ((vax_confdata & KA420_CFG_VIDOPT) != 0 &&
(cf->cf_flags & 1) == 0)
return 0;
break;
}
/* when already running as console, always fake things */
if ((vax_confdata & (KA420_CFG_L3CON | KA420_CFG_VIDOPT)) == 0
#if NWSDISPLAY > 0
&& cn_tab->cn_putc == wsdisplay_cnputc
#endif
) {
struct vsbus_softc *sc = device_private(parent);
sc->sc_mask = 0x08;
scb_fake(0x44, 0x15);
return 20;
} else {
/*
* Try to find the cursor chip by testing the flip-flop.
* If nonexistent, no glass tty.
*/
curcmd = (short *)va->va_addr;
cfgtst = (short *)vax_map_physmem(VS_CFGTST, 1);
curcmd[0] = PCCCMD_HSHI | PCCCMD_FOPB;
DELAY(300000);
tmp = cfgtst[0];
curcmd[0] = PCCCMD_TEST | PCCCMD_HSHI;
DELAY(300000);
tmp2 = cfgtst[0];
vax_unmap_physmem((vaddr_t)cfgtst, 1);
if (tmp2 != tmp)
return 20; /* Using periodic interrupt */
else
return 0;
}
}
/*
* Initialize anything necessary for an emulating wsdisplay to work (i.e.
* pick a font, initialize a rasops structure, setup the accessops callbacks.)
*/
static int
smg_setup_screen(struct smg_screen *ss)
{
struct rasops_info *ri = &ss->ss_ri;
int cookie;
static int
smg_setcursor(struct smg_screen *ss, struct wsdisplay_cursor *wdc)
{
uint16_t curfg[PCC_CURSOR_SIZE], curmask[PCC_CURSOR_SIZE];
int error;
if ((wdc->which & WSDISPLAY_CURSOR_DOCMAP) != 0) {
/* No cursor colormap since we are a B&W device. */
if (wdc->cmap.count != 0)
return EINVAL;
}
/*
* First, do the userland-kernel data transfers, so that we can fail
* if necessary before altering anything.
*/
if ((wdc->which & WSDISPLAY_CURSOR_DOSHAPE) != 0) {
if (wdc->size.x != PCC_CURSOR_SIZE ||
wdc->size.y != PCC_CURSOR_SIZE)
return EINVAL;
error = copyin(wdc->image, curfg, sizeof(curfg));
if (error != 0)
return error;
error = copyin(wdc->mask, curmask, sizeof(curmask));
if (error != 0)
return error;
}
static void
smg_blockmove(struct rasops_info *ri, u_int sx, u_int y, u_int dx, u_int cx,
u_int cy, int rop)
{
int width; /* add to get to same position in next line */
unsigned int *psrcLine, *pdstLine;
/* pointers to line with current src and dst */
unsigned int *psrc; /* pointer to current src longword */
unsigned int *pdst; /* pointer to current dst longword */
/* following used for looping through a line */
unsigned int startmask, endmask; /* masks for writing ends of dst */
int nlMiddle; /* whole longwords in dst */
int nl; /* temp copy of nlMiddle */
int xoffSrc; /* offset (>= 0, < 32) from which to
fetch whole longwords fetched in src */
int nstart; /* number of ragged bits at start of dst */
int nend; /* number of ragged bits at end of dst */
int srcStartOver; /* pulling nstart bits from src
overflows into the next word? */
width = SM_XWIDTH >> 5;
/* start at first scanline */
psrcLine = pdstLine = ((u_int *)ri->ri_bits) + (y * width);
/* x direction doesn't matter for < 1 longword */
if (cx <= 32) {
int srcBit, dstBit; /* bit offset of src and dst */
switch (vax_boardtype) {
case VAX_BTYP_410:
case VAX_BTYP_420:
case VAX_BTYP_43:
if ((vax_confdata & (KA420_CFG_L3CON | KA420_CFG_MULTU)) != 0)
break; /* doesn't use graphics console */
if ((vax_confdata & KA420_CFG_VIDOPT) != 0)
break; /* there is a color option */
/*
* Called very early to setup the glass tty as console.
* Because it's called before the VM system is initialized, virtual memory
* for the framebuffer can be stolen directly without disturbing anything.
*/
void
smgcninit(struct consdev *cndev)
{
struct smg_screen *ss = &smg_consscr;
vaddr_t ova;
long defattr;
struct rasops_info *ri;
extern vaddr_t virtual_avail;