BSD-SCCS END release
[unix-history] / usr / src / sys / hp300 / dev / grf_gb.c
CommitLineData
60f56dfc
KM
1/*
2 * Copyright (c) 1988 University of Utah.
030a8056
KB
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
60f56dfc
KM
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 *
6f16b9c3 12 * from: Utah $Hdr: grf_gb.c 1.18 93/08/13$
60f56dfc 13 *
2c0f281d 14 * @(#)grf_gb.c 8.4 (Berkeley) %G%
60f56dfc
KM
15 */
16
17#include "grf.h"
18#if NGRF > 0
19
20/*
21 * Graphics routines for the Gatorbox.
22 *
23 * Note: In the context of this system, "gator" and "gatorbox" both refer to
24 * HP 987x0 graphics systems. "Gator" is not used for high res mono.
25 * (as in 9837 Gator systems)
26 */
38a01dbe
KB
27#include <sys/param.h>
28#include <sys/errno.h>
60f56dfc 29
38a01dbe
KB
30#include <hp/dev/grfioctl.h>
31#include <hp/dev/grfvar.h>
60f56dfc 32
38a01dbe
KB
33#include <hp300/dev/grf_gbreg.h>
34#include <machine/cpu.h>
60f56dfc
KM
35
36#define CRTC_DATA_LENGTH 0x0e
37u_char crtc_init_data[CRTC_DATA_LENGTH] = {
38 0x29, 0x20, 0x23, 0x04, 0x30, 0x0b, 0x30,
39 0x30, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00
40};
41
42/*
43 * Initialize hardware.
44 * Must point g_display at a grfinfo structure describing the hardware.
45 * Returns 0 if hardware not present, non-zero ow.
46 */
47gb_init(gp, addr)
48 struct grf_softc *gp;
16a027eb 49 caddr_t addr;
60f56dfc
KM
50{
51 register struct gboxfb *gbp;
52 struct grfinfo *gi = &gp->g_display;
53 u_char *fbp, save;
54 int fboff;
16a027eb 55 extern caddr_t sctopa(), iomap();
60f56dfc
KM
56
57 gbp = (struct gboxfb *) addr;
16a027eb
MH
58 if (ISIIOVA(addr))
59 gi->gd_regaddr = (caddr_t) IIOP(addr);
60 else
61 gi->gd_regaddr = sctopa(vatosc(addr));
60f56dfc
KM
62 gi->gd_regsize = 0x10000;
63 gi->gd_fbwidth = 1024; /* XXX */
64 gi->gd_fbheight = 1024; /* XXX */
60f56dfc 65 gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight;
16a027eb
MH
66 fboff = (gbp->fbomsb << 8) | gbp->fbolsb;
67 gi->gd_fbaddr = (caddr_t) (*((u_char *)addr + fboff) << 16);
68 gp->g_regkva = addr;
69 gp->g_fbkva = iomap(gi->gd_fbaddr, gi->gd_fbsize);
60f56dfc
KM
70 gi->gd_dwidth = 1024; /* XXX */
71 gi->gd_dheight = 768; /* XXX */
72 gi->gd_planes = 0; /* how do we do this? */
73 /*
74 * The minimal register info here is from the Gatorbox X driver.
75 */
16a027eb 76 fbp = (u_char *) gp->g_fbkva;
60f56dfc
KM
77 gbp->write_protect = 0;
78 gbp->interrupt = 4; /** fb_enable ? **/
79 gbp->rep_rule = 3; /* GXcopy */
80 gbp->blink1 = 0xff;
81 gbp->blink2 = 0xff;
82
83 gb_microcode(gbp);
84
85 /*
86 * Find out how many colors are available by determining
87 * which planes are installed. That is, write all ones to
88 * a frame buffer location, see how many ones are read back.
89 */
90 save = *fbp;
91 *fbp = 0xFF;
92 gi->gd_colors = *fbp + 1;
93 *fbp = save;
94 return(1);
95}
96
97/*
98 * Program the 6845.
99 */
100gb_microcode(gbp)
101 register struct gboxfb *gbp;
102{
103 register int i;
104
105 for (i = 0; i < CRTC_DATA_LENGTH; i++) {
106 gbp->crtc_address = i;
107 gbp->crtc_data = crtc_init_data[i];
108 }
109}
110
111/*
112 * Change the mode of the display.
113 * Right now all we can do is grfon/grfoff.
114 * Return a UNIX error number or 0 for success.
115 */
6f16b9c3 116gb_mode(gp, cmd, data)
60f56dfc 117 register struct grf_softc *gp;
2c0f281d 118 int cmd;
6f16b9c3 119 caddr_t data;
60f56dfc
KM
120{
121 struct gboxfb *gbp;
122 int error = 0;
123
16a027eb 124 gbp = (struct gboxfb *) gp->g_regkva;
60f56dfc
KM
125 switch (cmd) {
126 case GM_GRFON:
127 gbp->sec_interrupt = 1;
128 break;
6f16b9c3 129
60f56dfc
KM
130 case GM_GRFOFF:
131 break;
6f16b9c3
MH
132
133 /*
134 * Remember UVA of mapping for GCDESCRIBE.
135 * XXX this should be per-process.
136 */
137 case GM_MAP:
138 gp->g_data = data;
139 break;
140
141 case GM_UNMAP:
142 gp->g_data = 0;
143 break;
144
145#ifdef HPUXCOMPAT
146 case GM_DESCRIBE:
147 {
148 struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
149 struct grfinfo *gi = &gp->g_display;
57ffde05 150 int i;
6f16b9c3
MH
151
152 /* feed it what HP-UX expects */
153 fi->id = gi->gd_id;
154 fi->mapsize = gi->gd_fbsize;
155 fi->dwidth = gi->gd_dwidth;
156 fi->dlength = gi->gd_dheight;
157 fi->width = gi->gd_fbwidth;
158 fi->length = gi->gd_fbheight;
159 fi->bpp = NBBY;
160 fi->xlen = (fi->width * fi->bpp) / NBBY;
161 fi->npl = gi->gd_planes;
162 fi->bppu = fi->npl;
163 fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
164 bcopy("HP98700", fi->name, 8);
165 fi->attr = 2; /* HW block mover */
166 /*
167 * If mapped, return the UVA where mapped.
168 */
169 if (gp->g_data) {
170 fi->regbase = gp->g_data;
171 fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
172 } else {
173 fi->fbbase = 0;
174 fi->regbase = 0;
175 }
176 for (i = 0; i < 6; i++)
177 fi->regions[i] = 0;
178 break;
179 }
180#endif
181
60f56dfc
KM
182 default:
183 error = EINVAL;
184 break;
185 }
186 return(error);
187}
188
189#endif