1 /* $NetBSD: grf_machdep.c,v 1.12 1999/03/16 16:30:18 minoura 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. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * from: Utah $Hdr: grf_machdep.c 1.1 92/01/21 41 * 42 * @(#)grf_machdep.c 8.2 (Berkeley) 1/12/94 43 */ 44 45 /* 46 * Graphics display driver for the HP300/400 DIO/DIO-II based machines. 47 * This is the hardware-dependent configuration portion of the driver. 48 */ 49 50 #include <sys/param.h> 51 #include <sys/systm.h> 52 #include <sys/device.h> 53 54 #include <machine/grfioctl.h> 55 #include <x68k/dev/grfvar.h> 56 #include <x68k/x68k/iodevice.h> 57 58 /* 59 * false when initing for the console. 60 */ 61 extern int x68k_realconfig; 62 int x68k_config_found __P((struct cfdata *, struct device *, 63 void *, cfprint_t)); 64 65 int grfbusprint __P((void *auxp, const char *)); 66 int grfbusmatch __P((struct device *, struct cfdata *, void *)); 67 void grfbusattach __P((struct device *, struct device *, void *)); 68 int grfbussearch __P((struct device *, struct cfdata *, void *)); 69 70 void grfattach __P((struct device *, struct device *, void *)); 71 int grfmatch __P((struct device *, struct cfdata *, void *)); 72 int grfprint __P((void *, const char *)); 73 74 void grfconfig __P((struct device *)); 75 int grfinit __P((void *, int)); 76 77 struct cfattach grfbus_ca = { 78 sizeof(struct device), grfbusmatch, grfbusattach 79 }; 80 81 struct cfattach grf_ca = { 82 sizeof(struct grf_softc), grfmatch, grfattach 83 }; 84 85 /* 86 * only used in console init. 87 */ 88 static struct cfdata *cfdata_gbus = NULL; 89 static struct cfdata *cfdata_grf = NULL; 90 91 extern struct cfdriver grfbus_cd; 92 93 int 94 grfbusmatch(pdp, cfp, auxp) 95 struct device *pdp; 96 struct cfdata *cfp; 97 void *auxp; 98 { 99 if (strcmp(auxp, grfbus_cd.cd_name)) 100 return(0); 101 102 if((x68k_realconfig == 0) || (cfdata_gbus == NULL)) { 103 /* 104 * Probe layers we depend on 105 */ 106 if(x68k_realconfig == 0) { 107 cfdata_gbus = cfp; 108 } 109 } 110 return(1); /* Always there */ 111 } 112 113 void 114 grfbusattach(pdp, dp, auxp) 115 struct device *pdp, *dp; 116 void *auxp; 117 { 118 int i; 119 120 if (dp == NULL) { 121 i = 0; 122 x68k_config_found(cfdata_gbus, NULL, (void*)&i, grfbusprint); 123 } else { 124 printf("\n"); 125 config_search(grfbussearch, dp, NULL); 126 } 127 } 128 129 int 130 grfbussearch(dp, match, aux) 131 struct device *dp; 132 struct cfdata *match; 133 134 void *aux; 135 { 136 int i = 0; 137 config_found(dp, (void*)&i, grfbusprint); 138 return (0); 139 } 140 141 int 142 grfbusprint(auxp, name) 143 void *auxp; 144 const char *name; 145 { 146 if(name == NULL) 147 return(UNCONF); 148 return(QUIET); 149 } 150 151 static struct grf_softc congrf; 152 /* 153 * XXX called from ite console init routine. 154 * Does just what configure will do later but without printing anything. 155 */ 156 void 157 grfconfig(dp) 158 struct device *dp; 159 { 160 int unit; 161 if (!dp) 162 dp = (void *)&congrf; 163 unit = dp->dv_unit; 164 165 grfinit(dp, unit); /* XXX */ 166 } 167 168 /* 169 * Normal init routine called by configure() code 170 */ 171 int 172 grfmatch(parent, cfp, aux) 173 struct device *parent; 174 struct cfdata *cfp; 175 void *aux; 176 { 177 /* XXX console at grf0 */ 178 if (x68k_realconfig == 0) { 179 if (cfp->cf_unit != 0) 180 return(0); 181 cfdata_grf = cfp; 182 } 183 return(1); 184 } 185 186 void 187 grfattach(parent, dp, aux) 188 struct device *parent; 189 struct device *dp; 190 void *aux; 191 { 192 /* static struct grf_softc congrf;*/ 193 struct grf_softc *gp; 194 195 grfconfig(dp); 196 /* 197 * Handle exeption case: early console init 198 */ 199 if(dp == NULL) { 200 /* Attach console ite */ 201 x68k_config_found(cfdata_grf, NULL, &congrf, grfprint); 202 return; 203 } 204 gp = (struct grf_softc *)dp; 205 printf(": %d x %d ", gp->g_display.gd_dwidth, 206 gp->g_display.gd_dheight); 207 if (gp->g_display.gd_colors == 2) 208 printf("monochrome"); 209 else 210 printf("%d colors", gp->g_display.gd_colors); 211 printf(" %s display\n", gp->g_sw->gd_desc); 212 213 /* 214 * try and attach an ite 215 */ 216 config_found(dp, gp, grfprint); 217 } 218 219 int 220 grfprint(auxp, pnp) 221 void *auxp; 222 const char *pnp; 223 { 224 if(pnp) 225 printf("ite at %s", pnp); 226 return(UNCONF); 227 } 228 229 int 230 grfinit(dp, unit) 231 void *dp; 232 int unit; 233 { 234 struct grf_softc *gp = dp; 235 register struct grfsw *gsw; 236 caddr_t addr; 237 238 if (unit == 0) 239 addr = (caddr_t)IODEVbase->tvram; 240 else 241 addr = (caddr_t)IODEVbase->gvram; 242 243 gsw = &grfsw[unit]; 244 if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) { 245 gp->g_sw = gsw; 246 gp->g_display.gd_id = gsw->gd_swid; 247 gp->g_flags = GF_ALIVE; 248 return(1); 249 } 250 return(0); 251 } 252