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