xref: /csrg-svn/sys/hp300/dev/grf_machdep.c (revision 53931)
1*53931Shibler /*
2*53931Shibler  * Copyright (c) 1991 University of Utah.
3*53931Shibler  * Copyright (c) 1990 The Regents of the University of California.
4*53931Shibler  * All rights reserved.
5*53931Shibler  *
6*53931Shibler  * This code is derived from software contributed to Berkeley by
7*53931Shibler  * the Systems Programming Group of the University of Utah Computer
8*53931Shibler  * Science Department.
9*53931Shibler  *
10*53931Shibler  * %sccs.include.redist.c%
11*53931Shibler  *
12*53931Shibler  * from: Utah $Hdr: grf_machdep.c 1.1 92/01/21
13*53931Shibler  *
14*53931Shibler  *	@(#)grf_machdep.c	7.1 (Berkeley) 06/05/92
15*53931Shibler  */
16*53931Shibler 
17*53931Shibler /*
18*53931Shibler  * Graphics display driver for the HP300/400 DIO/DIO-II based machines.
19*53931Shibler  * This is the hardware-dependent configuration portion of the driver.
20*53931Shibler  */
21*53931Shibler 
22*53931Shibler #include "grf.h"
23*53931Shibler #if NGRF > 0
24*53931Shibler 
25*53931Shibler #include "sys/param.h"
26*53931Shibler 
27*53931Shibler #include "hp/dev/device.h"
28*53931Shibler #include "hp/dev/grfioctl.h"
29*53931Shibler #include "hp/dev/grfvar.h"
30*53931Shibler #include "hp/dev/grfreg.h"
31*53931Shibler 
32*53931Shibler int grfprobe();
33*53931Shibler struct	driver grfdriver = { grfprobe, "grf" };
34*53931Shibler 
35*53931Shibler /*
36*53931Shibler  * XXX called from ite console init routine.
37*53931Shibler  * Does just what configure will do later but without printing anything.
38*53931Shibler  */
39*53931Shibler grfconfig()
40*53931Shibler {
41*53931Shibler 	register caddr_t addr;
42*53931Shibler 	register struct hp_hw *hw;
43*53931Shibler 	register struct hp_device *hd, *nhd;
44*53931Shibler 
45*53931Shibler 	for (hw = sc_table; hw->hw_type; hw++) {
46*53931Shibler 	        if (!HW_ISDEV(hw, D_BITMAP))
47*53931Shibler 			continue;
48*53931Shibler 		/*
49*53931Shibler 		 * Found one, now match up with a logical unit number
50*53931Shibler 		 */
51*53931Shibler 		nhd = NULL;
52*53931Shibler 		addr = hw->hw_kva;
53*53931Shibler 		for (hd = hp_dinit; hd->hp_driver; hd++) {
54*53931Shibler 			if (hd->hp_driver != &grfdriver || hd->hp_alive)
55*53931Shibler 				continue;
56*53931Shibler 			/*
57*53931Shibler 			 * Wildcarded.  If first, remember as possible match.
58*53931Shibler 			 */
59*53931Shibler 			if (hd->hp_addr == NULL) {
60*53931Shibler 				if (nhd == NULL)
61*53931Shibler 					nhd = hd;
62*53931Shibler 				continue;
63*53931Shibler 			}
64*53931Shibler 			/*
65*53931Shibler 			 * Not wildcarded.
66*53931Shibler 			 * If exact match done searching, else keep looking.
67*53931Shibler 			 */
68*53931Shibler 			if (sctova(hd->hp_addr) == addr) {
69*53931Shibler 				nhd = hd;
70*53931Shibler 				break;
71*53931Shibler 			}
72*53931Shibler 		}
73*53931Shibler 		/*
74*53931Shibler 		 * Found a match, initialize
75*53931Shibler 		 */
76*53931Shibler 		if (nhd && grfinit(addr, nhd->hp_unit))
77*53931Shibler 			nhd->hp_addr = addr;
78*53931Shibler 	}
79*53931Shibler }
80*53931Shibler 
81*53931Shibler /*
82*53931Shibler  * Normal init routine called by configure() code
83*53931Shibler  */
84*53931Shibler grfprobe(hd)
85*53931Shibler 	struct hp_device *hd;
86*53931Shibler {
87*53931Shibler 	struct grf_softc *gp = &grf_softc[hd->hp_unit];
88*53931Shibler 
89*53931Shibler 	if ((gp->g_flags & GF_ALIVE) == 0 &&
90*53931Shibler 	    !grfinit(hd->hp_addr, hd->hp_unit))
91*53931Shibler 		return(0);
92*53931Shibler 	printf("grf%d: %d x %d ", hd->hp_unit,
93*53931Shibler 	       gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
94*53931Shibler 	if (gp->g_display.gd_colors == 2)
95*53931Shibler 		printf("monochrome");
96*53931Shibler 	else
97*53931Shibler 		printf("%d color", gp->g_display.gd_colors);
98*53931Shibler 	printf(" %s display\n", gp->g_sw->gd_desc);
99*53931Shibler 	return(1);
100*53931Shibler }
101*53931Shibler 
102*53931Shibler grfinit(addr, unit)
103*53931Shibler 	caddr_t addr;
104*53931Shibler {
105*53931Shibler 	struct grf_softc *gp = &grf_softc[unit];
106*53931Shibler 	register struct grfsw *gsw;
107*53931Shibler 	struct grfreg *gr;
108*53931Shibler 
109*53931Shibler 	gr = (struct grfreg *) addr;
110*53931Shibler 	if (gr->gr_id != GRFHWID)
111*53931Shibler 		return(0);
112*53931Shibler 	for (gsw = grfsw; gsw < &grfsw[ngrfsw]; gsw++)
113*53931Shibler 		if (gsw->gd_hwid == gr->gr_id2)
114*53931Shibler 			break;
115*53931Shibler 	if (gsw < &grfsw[ngrfsw] && (*gsw->gd_init)(gp, addr)) {
116*53931Shibler 		gp->g_sw = gsw;
117*53931Shibler 		gp->g_display.gd_id = gsw->gd_swid;
118*53931Shibler 		gp->g_flags = GF_ALIVE;
119*53931Shibler 		return(1);
120*53931Shibler 	}
121*53931Shibler 	return(0);
122*53931Shibler }
123*53931Shibler #endif
124