1 /* $NetBSD: grf_machdep.c,v 1.32 2012/10/27 17:18:13 chs 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.32 2012/10/27 17:18:13 chs 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 /* grfbus: is this necessary? */ 61 int grfbusprint(void *, const char *); 62 int grfbusmatch(device_t, cfdata_t, void *); 63 void grfbusattach(device_t, device_t, void *); 64 int grfbussearch(device_t, cfdata_t, const int *, void *); 65 66 /* grf itself */ 67 int grfmatch(device_t, cfdata_t, void *); 68 void grfattach(device_t, device_t, void *); 69 int grfprint(void *, const char *); 70 71 static int grfinit(struct grf_softc *, int); 72 73 CFATTACH_DECL_NEW(grfbus, 0, 74 grfbusmatch, grfbusattach, NULL, NULL); 75 76 CFATTACH_DECL_NEW(grf, sizeof(struct grf_softc), 77 grfmatch, grfattach, NULL, NULL); 78 79 extern struct cfdriver grfbus_cd; 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_ia(grfbussearch, self, "grfb", NULL); 96 } 97 98 int 99 grfbussearch(device_t self, cfdata_t match, const int *ldesc, void *aux) 100 { 101 102 config_found(self, &match->cf_loc[GRFBCF_ADDR], grfbusprint); 103 return (0); 104 } 105 106 int 107 grfbusprint(void *aux, const char *name) 108 { 109 110 if (name == NULL) 111 return (UNCONF); 112 return (QUIET); 113 } 114 115 /* 116 * Normal init routine called by configure() code 117 */ 118 int 119 grfmatch(device_t parent, cfdata_t cfp, void *aux) 120 { 121 int addr; 122 123 addr = cfp->cf_loc[GRFBCF_ADDR]; 124 if (addr < 0 || addr > ngrfsw) 125 return 0; 126 127 return 1; 128 } 129 130 struct grf_softc congrf; 131 132 void 133 grfattach(device_t parent, device_t self, void *aux) 134 { 135 struct grf_softc *gp; 136 struct cfdata *cf; 137 int addr; 138 139 cf = device_cfdata(self); 140 addr = cf->cf_loc[GRFBCF_ADDR]; 141 142 gp = device_private(self); 143 gp->g_device = self; 144 gp->g_cfaddr = addr; 145 grfinit(gp, addr); 146 147 aprint_normal(": %d x %d ", 148 gp->g_display.gd_dwidth, gp->g_display.gd_dheight); 149 if (gp->g_display.gd_colors == 2) 150 aprint_normal("monochrome"); 151 else 152 aprint_normal("%d colors", gp->g_display.gd_colors); 153 aprint_normal(" %s display\n", gp->g_sw->gd_desc); 154 155 /* 156 * try and attach an ite 157 */ 158 config_found(self, gp, grfprint); 159 } 160 161 int 162 grfprint(void *aux, const char *pnp) 163 { 164 165 if (pnp) 166 aprint_normal("ite at %s", pnp); 167 return UNCONF; 168 } 169 170 int 171 grfinit(struct grf_softc *gp, int cfaddr) 172 { 173 struct grfsw *gsw; 174 void *addr; 175 176 if (cfaddr == 0) 177 addr = (void *)__UNVOLATILE(IODEVbase->tvram); 178 else 179 addr = (void *)__UNVOLATILE(IODEVbase->gvram); 180 181 gsw = &grfsw[cfaddr]; 182 if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) { 183 gp->g_sw = gsw; 184 gp->g_display.gd_id = gsw->gd_swid; 185 gp->g_flags = GF_ALIVE; 186 return 1; 187 } 188 189 return 0; 190 } 191 192 void 193 grf_config_console(void) 194 { 195 grfinit(&congrf, 0); 196 } 197