xref: /original-bsd/sys/hp300/dev/grf_tc.c (revision a64a4258)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: grf_tc.c 1.20 93/08/13$
13  *
14  *	@(#)grf_tc.c	8.4 (Berkeley) 01/12/94
15  */
16 
17 #include "grf.h"
18 #if NGRF > 0
19 
20 /*
21  * Graphics routines for TOPCAT and CATSEYE frame buffers
22  */
23 #include <sys/param.h>
24 #include <sys/errno.h>
25 
26 #include <hp/dev/grfioctl.h>
27 #include <hp/dev/grfvar.h>
28 #include <hp/dev/grfreg.h>
29 #include <hp300/dev/grf_tcreg.h>
30 
31 #include <machine/cpu.h>
32 
33 /*
34  * Initialize hardware.
35  * Must fill in the grfinfo structure in g_softc.
36  * Returns 0 if hardware not present, non-zero ow.
37  */
38 tc_init(gp, addr)
39 	struct grf_softc *gp;
40 	caddr_t addr;
41 {
42 	register struct tcboxfb *tp = (struct tcboxfb *) addr;
43 	struct grfinfo *gi = &gp->g_display;
44 	volatile u_char *fbp;
45 	u_char save;
46 	int fboff;
47 	extern caddr_t sctopa(), iomap();
48 
49 	if (ISIIOVA(addr))
50 		gi->gd_regaddr = (caddr_t) IIOP(addr);
51 	else
52 		gi->gd_regaddr = sctopa(vatosc(addr));
53 	gi->gd_regsize = 0x10000;
54 	gi->gd_fbwidth = (tp->fbwmsb << 8) | tp->fbwlsb;
55 	gi->gd_fbheight = (tp->fbhmsb << 8) | tp->fbhlsb;
56 	gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight;
57 	fboff = (tp->fbomsb << 8) | tp->fbolsb;
58 	gi->gd_fbaddr = (caddr_t) (*((u_char *)addr + fboff) << 16);
59 	if (gi->gd_regaddr >= (caddr_t)DIOIIBASE) {
60 		/*
61 		 * For DIO II space the fbaddr just computed is the offset
62 		 * from the select code base (regaddr) of the framebuffer.
63 		 * Hence it is also implicitly the size of the register set.
64 		 */
65 		gi->gd_regsize = (int) gi->gd_fbaddr;
66 		gi->gd_fbaddr += (int) gi->gd_regaddr;
67 		gp->g_regkva = addr;
68 		gp->g_fbkva = addr + gi->gd_regsize;
69 	} else {
70 		/*
71 		 * For DIO space we need to map the seperate framebuffer.
72 		 */
73 		gp->g_regkva = addr;
74 		gp->g_fbkva = iomap(gi->gd_fbaddr, gi->gd_fbsize);
75 	}
76 	gi->gd_dwidth = (tp->dwmsb << 8) | tp->dwlsb;
77 	gi->gd_dheight = (tp->dhmsb << 8) | tp->dhlsb;
78 	gi->gd_planes = tp->num_planes;
79 	gi->gd_colors = 1 << gi->gd_planes;
80 	if (gi->gd_colors == 1) {
81 		fbp = (u_char *) gp->g_fbkva;
82 		tp->wen = ~0;
83 		tp->prr = 0x3;
84 		tp->fben = ~0;
85 		save = *fbp;
86 		*fbp = 0xFF;
87 		gi->gd_colors = *fbp + 1;
88 		*fbp = save;
89 	}
90 	return(1);
91 }
92 
93 /*
94  * Change the mode of the display.
95  * Right now all we can do is grfon/grfoff.
96  * Return a UNIX error number or 0 for success.
97  * Function may not be needed anymore.
98  */
99 /*ARGSUSED*/
100 tc_mode(gp, cmd, data)
101 	struct grf_softc *gp;
102 	int cmd;
103 	caddr_t data;
104 {
105 	int error = 0;
106 
107 	switch (cmd) {
108 	case GM_GRFON:
109 	case GM_GRFOFF:
110 		break;
111 
112 	/*
113 	 * Remember UVA of mapping for GCDESCRIBE.
114 	 * XXX this should be per-process.
115 	 */
116 	case GM_MAP:
117 		gp->g_data = data;
118 		break;
119 
120 	case GM_UNMAP:
121 		gp->g_data = 0;
122 		break;
123 
124 #ifdef HPUXCOMPAT
125 	case GM_DESCRIBE:
126 	{
127 		struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
128 		struct grfinfo *gi = &gp->g_display;
129 		int i;
130 
131 		/* feed it what HP-UX expects */
132 		fi->id = gi->gd_id;
133 		fi->mapsize = gi->gd_fbsize;
134 		fi->dwidth = gi->gd_dwidth;
135 		fi->dlength = gi->gd_dheight;
136 		fi->width = gi->gd_fbwidth;
137 		fi->length = gi->gd_fbheight;
138 		fi->bpp = NBBY;
139 		fi->xlen = (fi->width * fi->bpp) / NBBY;
140 		fi->npl = gi->gd_planes;
141 		fi->bppu = fi->npl;
142 		fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
143 		/* XXX */
144 		switch (gp->g_sw->gd_hwid) {
145 		case GID_HRCCATSEYE:
146 			bcopy("HP98550", fi->name, 8);
147 			break;
148 		case GID_LRCATSEYE:
149 			bcopy("HP98549", fi->name, 8);
150 			break;
151 		case GID_HRMCATSEYE:
152 			bcopy("HP98548", fi->name, 8);
153 			break;
154 		case GID_TOPCAT:
155 			switch (gi->gd_colors) {
156 			case 64:
157 				bcopy("HP98547", fi->name, 8);
158 				break;
159 			case 16:
160 				bcopy("HP98545", fi->name, 8);
161 				break;
162 			case 2:
163 				bcopy("HP98544", fi->name, 8);
164 				break;
165 			}
166 			break;
167 		}
168 		fi->attr = 2;	/* HW block mover */
169 		/*
170 		 * If mapped, return the UVA where mapped.
171 		 */
172 		if (gp->g_data) {
173 			fi->regbase = gp->g_data;
174 			fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
175 		} else {
176 			fi->fbbase = 0;
177 			fi->regbase = 0;
178 		}
179 		for (i = 0; i < 6; i++)
180 			fi->regions[i] = 0;
181 		break;
182 	}
183 #endif
184 
185 	default:
186 		error = EINVAL;
187 		break;
188 	}
189 	return(error);
190 }
191 #endif
192