Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: grf_machdep.c,v 1.35 2022/05/26 14:33:29 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1991 University of Utah.
      5  * Copyright (c) 1990, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah $Hdr: grf_machdep.c 1.1 92/01/21
     37  *
     38  *	@(#)grf_machdep.c	8.2 (Berkeley) 1/12/94
     39  */
     40 
     41 /*
     42  * Graphics display driver for the HP300/400 DIO/DIO-II based machines.
     43  * This is the hardware-dependent configuration portion of the driver.
     44  */
     45 
     46 #include <sys/cdefs.h>
     47 __KERNEL_RCSID(0, "$NetBSD: grf_machdep.c,v 1.35 2022/05/26 14:33:29 tsutsui Exp $");
     48 
     49 #include "locators.h"
     50 
     51 #include <sys/param.h>
     52 #include <sys/systm.h>
     53 #include <sys/device.h>
     54 
     55 #include <machine/autoconf.h>
     56 #include <machine/grfioctl.h>
     57 #include <x68k/dev/grfvar.h>
     58 #include <x68k/x68k/iodevice.h>
     59 
     60 #include "ioconf.h"
     61 
     62 /* grfbus: is this necessary? */
     63 int grfbusprint(void *, const char *);
     64 int grfbusmatch(device_t, cfdata_t, void *);
     65 void grfbusattach(device_t, device_t, void *);
     66 int grfbussearch(device_t, cfdata_t, const int *, void *);
     67 
     68 /* grf itself */
     69 int grfmatch(device_t, cfdata_t, void *);
     70 void grfattach(device_t, device_t, void *);
     71 int grfprint(void *, const char *);
     72 
     73 static int grfinit(struct grf_softc *, int);
     74 
     75 CFATTACH_DECL_NEW(grfbus, 0,
     76     grfbusmatch, grfbusattach, NULL, NULL);
     77 
     78 CFATTACH_DECL_NEW(grf, sizeof(struct grf_softc),
     79     grfmatch, grfattach, NULL, NULL);
     80 
     81 int
     82 grfbusmatch(device_t parent, cfdata_t cf, void *aux)
     83 {
     84 	if (strcmp(aux, grfbus_cd.cd_name))
     85 		return (0);
     86 
     87 	return (1);
     88 }
     89 
     90 void
     91 grfbusattach(device_t parent, device_t self, void *aux)
     92 {
     93 
     94 	aprint_normal("\n");
     95 	config_search(self, NULL,
     96 	    CFARGS(.search = grfbussearch));
     97 }
     98 
     99 int
    100 grfbussearch(device_t self, cfdata_t match, const int *ldesc, void *aux)
    101 {
    102 
    103 	config_found(self, &match->cf_loc[GRFBCF_ADDR], grfbusprint, CFARGS_NONE);
    104 	return (0);
    105 }
    106 
    107 int
    108 grfbusprint(void *aux, const char *name)
    109 {
    110 
    111 	if (name == NULL)
    112 		return (UNCONF);
    113 	return (QUIET);
    114 }
    115 
    116 /*
    117  * Normal init routine called by configure() code
    118  */
    119 int
    120 grfmatch(device_t parent, cfdata_t cfp, void *aux)
    121 {
    122 	int addr;
    123 
    124 	addr = cfp->cf_loc[GRFBCF_ADDR];
    125 	if (addr < 0 || addr > ngrfsw)
    126 		return 0;
    127 
    128 	return 1;
    129 }
    130 
    131 struct grf_softc congrf;
    132 
    133 void
    134 grfattach(device_t parent, device_t self, void *aux)
    135 {
    136 	struct grf_softc *gp;
    137 	struct cfdata *cf;
    138 	int addr;
    139 
    140 	cf = device_cfdata(self);
    141 	addr = cf->cf_loc[GRFBCF_ADDR];
    142 
    143 	gp = device_private(self);
    144 	gp->g_device = self;
    145 	gp->g_cfaddr = addr;
    146 	grfinit(gp, addr);
    147 
    148 	aprint_normal(": %d x %d ",
    149 		gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
    150 	if (gp->g_display.gd_colors == 2)
    151 		aprint_normal("monochrome");
    152 	else
    153 		aprint_normal("%d colors", gp->g_display.gd_colors);
    154 	aprint_normal(" %s display\n", gp->g_sw->gd_desc);
    155 
    156 	/*
    157 	 * try and attach an ite
    158 	 */
    159 	config_found(self, gp, grfprint, CFARGS_NONE);
    160 }
    161 
    162 int
    163 grfprint(void *aux, const char *pnp)
    164 {
    165 
    166 	if (pnp)
    167 		aprint_normal("ite at %s", pnp);
    168 	return UNCONF;
    169 }
    170 
    171 int
    172 grfinit(struct grf_softc *gp, int cfaddr)
    173 {
    174 	struct grfsw *gsw;
    175 	void *addr;
    176 
    177 	if (cfaddr == 0)
    178 		addr = (void *)__UNVOLATILE(IODEVbase->tvram);
    179 	else
    180 		addr = (void *)__UNVOLATILE(IODEVbase->gvram);
    181 
    182 	gsw = &grfsw[cfaddr];
    183 	if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
    184 		gp->g_sw = gsw;
    185 		gp->g_display.gd_id = gsw->gd_swid;
    186 		gp->g_flags = GF_ALIVE;
    187 		return 1;
    188 	}
    189 
    190 	return 0;
    191 }
    192 
    193 void
    194 grf_config_console(void)
    195 {
    196 	grfinit(&congrf, 0);
    197 }
    198