1 /* $NetBSD: grf_machdep.c,v 1.8 1997/10/12 14:45:43 oki 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 <x68k/dev/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 63 int grfbusprint __P((void *auxp, const char *)); 64 int grfbusmatch __P((struct device *, void *, void *)); 65 void grfbusattach __P((struct device *, struct device *, void *)); 66 int grfbussearch __P((struct device *, void *, void *)); 67 68 void grfattach __P((struct device *, struct device *, void *)); 69 int grfmatch __P((struct device *, void *, void *)); 70 int grfprint __P((void *, const char *)); 71 72 void grfconfig __P((struct device *)); 73 int grfinit __P((void *, int)); 74 75 struct cfattach grfbus_ca = { 76 sizeof(struct device), grfbusmatch, grfbusattach 77 }; 78 79 struct cfdriver grfbus_cd = { 80 NULL, "grfbus", DV_DULL 81 }; 82 83 struct cfattach grf_ca = { 84 sizeof(struct grf_softc), grfmatch, grfattach 85 }; 86 87 struct cfdriver grf_cd = { 88 NULL, "grf", DV_DULL 89 }; 90 91 /* 92 * only used in console init. 93 */ 94 static struct cfdata *cfdata_gbus = NULL; 95 static struct cfdata *cfdata_grf = NULL; 96 97 int 98 grfbusmatch(pdp, match, auxp) 99 struct device *pdp; 100 void *match, *auxp; 101 { 102 struct cfdata *cfp = match; 103 104 if (strcmp(auxp, grfbus_cd.cd_name)) 105 return(0); 106 107 if((x68k_realconfig == 0) || (cfdata_gbus == NULL)) { 108 /* 109 * Probe layers we depend on 110 */ 111 if(x68k_realconfig == 0) { 112 cfdata_gbus = cfp; 113 } 114 } 115 return(1); /* Always there */ 116 } 117 118 void 119 grfbusattach(pdp, dp, auxp) 120 struct device *pdp, *dp; 121 void *auxp; 122 { 123 int i; 124 125 if (dp == NULL) { 126 i = 0; 127 x68k_config_found(cfdata_gbus, NULL, (void*)&i, grfbusprint); 128 } else { 129 printf("\n"); 130 config_search(grfbussearch, dp, NULL); 131 } 132 } 133 134 int 135 grfbussearch(dp, match, aux) 136 struct device *dp; 137 void *match, *aux; 138 { 139 int i = 0; 140 config_found(dp, (void*)&i, grfbusprint); 141 return (0); 142 } 143 144 int 145 grfbusprint(auxp, name) 146 void *auxp; 147 const char *name; 148 { 149 if(name == NULL) 150 return(UNCONF); 151 return(QUIET); 152 } 153 154 static struct grf_softc congrf; 155 /* 156 * XXX called from ite console init routine. 157 * Does just what configure will do later but without printing anything. 158 */ 159 void 160 grfconfig(dp) 161 struct device *dp; 162 { 163 int unit; 164 if (!dp) 165 dp = (void *)&congrf; 166 unit = dp->dv_unit; 167 168 grfinit(dp, unit); /* XXX */ 169 } 170 171 /* 172 * Normal init routine called by configure() code 173 */ 174 int 175 grfmatch(parent, match, aux) 176 struct device *parent; 177 void *match, *aux; 178 { 179 struct cfdata *cfp = match; 180 181 /* XXX console at grf0 */ 182 if (x68k_realconfig == 0) { 183 if (cfp->cf_unit != 0) 184 return(0); 185 cfdata_grf = cfp; 186 } 187 return(1); 188 } 189 190 void 191 grfattach(parent, dp, aux) 192 struct device *parent; 193 struct device *dp; 194 void *aux; 195 { 196 /* static struct grf_softc congrf;*/ 197 struct grf_softc *gp; 198 199 grfconfig(dp); 200 /* 201 * Handle exeption case: early console init 202 */ 203 if(dp == NULL) { 204 /* Attach console ite */ 205 x68k_config_found(cfdata_grf, NULL, &congrf, grfprint); 206 return; 207 } 208 gp = (struct grf_softc *)dp; 209 printf(": %d x %d ", gp->g_display.gd_dwidth, 210 gp->g_display.gd_dheight); 211 if (gp->g_display.gd_colors == 2) 212 printf("monochrome"); 213 else 214 printf("%d colors", gp->g_display.gd_colors); 215 printf(" %s display\n", gp->g_sw->gd_desc); 216 217 /* 218 * try and attach an ite 219 */ 220 config_found(dp, gp, grfprint); 221 } 222 223 int 224 grfprint(auxp, pnp) 225 void *auxp; 226 const char *pnp; 227 { 228 if(pnp) 229 printf("ite at %s", pnp); 230 return(UNCONF); 231 } 232 233 int 234 grfinit(dp, unit) 235 void *dp; 236 int unit; 237 { 238 struct grf_softc *gp = dp; 239 register struct grfsw *gsw; 240 caddr_t addr; 241 242 if (unit == 0) 243 addr = (caddr_t)IODEVbase->tvram; 244 else 245 addr = (caddr_t)IODEVbase->gvram; 246 247 gsw = &grfsw[unit]; 248 if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) { 249 gp->g_sw = gsw; 250 gp->g_display.gd_id = gsw->gd_swid; 251 gp->g_flags = GF_ALIVE; 252 return(1); 253 } 254 return(0); 255 } 256