BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / hp300 / dev / grf_hy.c
CommitLineData
9acfa6cd
MH
1/*
2 * Copyright (c) 1991 University of Utah.
ad787160
C
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
9acfa6cd
MH
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 and Mark Davies of the Department of Computer
9 * Science, Victoria University of Wellington, New Zealand.
10 *
ad787160
C
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. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
9acfa6cd 38 *
6f16b9c3 39 * from: Utah $Hdr: grf_hy.c 1.2 93/08/13$
9acfa6cd 40 *
ed554bc5 41 * @(#)grf_hy.c 8.4 (Berkeley) 1/12/94
9acfa6cd
MH
42 */
43
44#include "grf.h"
45#if NGRF > 0
46
47/*
48 * Graphics routines for HYPERION frame buffer
49 */
38a01dbe
KB
50#include <sys/param.h>
51#include <sys/errno.h>
9acfa6cd 52
38a01dbe
KB
53#include <hp/dev/grfioctl.h>
54#include <hp/dev/grfvar.h>
55#include <hp300/dev/grf_hyreg.h>
9acfa6cd 56
38a01dbe 57#include <machine/cpu.h>
9acfa6cd
MH
58
59caddr_t badhyaddr = (caddr_t) -1;
60
61/*
62 * Initialize hardware.
63 * Must fill in the grfinfo structure in g_softc.
64 * Returns 0 if hardware not present, non-zero ow.
65 */
66hy_init(gp, addr)
67 struct grf_softc *gp;
68 caddr_t addr;
69{
70 register struct hyboxfb *hy = (struct hyboxfb *) addr;
71 struct grfinfo *gi = &gp->g_display;
72 int fboff;
73 extern caddr_t sctopa(), iomap();
74
75 if (ISIIOVA(addr))
76 gi->gd_regaddr = (caddr_t) IIOP(addr);
77 else
78 gi->gd_regaddr = sctopa(vatosc(addr));
79 gi->gd_regsize = 0x20000;
80 gi->gd_fbwidth = (hy->fbwmsb << 8) | hy->fbwlsb;
81 gi->gd_fbheight = (hy->fbhmsb << 8) | hy->fbhlsb;
82 gi->gd_fbsize = (gi->gd_fbwidth * gi->gd_fbheight) >> 3;
83 fboff = (hy->fbomsb << 8) | hy->fbolsb;
84 gi->gd_fbaddr = (caddr_t) (*((u_char *)addr + fboff) << 16);
85 if (gi->gd_regaddr >= (caddr_t)DIOIIBASE) {
86 /*
87 * For DIO II space the fbaddr just computed is the offset
88 * from the select code base (regaddr) of the framebuffer.
89 * Hence it is also implicitly the size of the register set.
90 */
91 gi->gd_regsize = (int) gi->gd_fbaddr;
92 gi->gd_fbaddr += (int) gi->gd_regaddr;
93 gp->g_regkva = addr;
94 gp->g_fbkva = addr + gi->gd_regsize;
95 } else {
96 /*
97 * For DIO space we need to map the seperate framebuffer.
98 */
99 gp->g_regkva = addr;
100 gp->g_fbkva = iomap(gi->gd_fbaddr, gi->gd_fbsize);
101 }
102 gi->gd_dwidth = (hy->dwmsb << 8) | hy->dwlsb;
103 gi->gd_dheight = (hy->dhmsb << 8) | hy->dhlsb;
104 gi->gd_planes = hy->num_planes;
105 gi->gd_colors = 1 << gi->gd_planes;
106
107 return(1);
108}
109
110/*
111 * Change the mode of the display.
112 * Right now all we can do is grfon/grfoff.
113 * Return a UNIX error number or 0 for success.
114 * Function may not be needed anymore.
115 */
6f16b9c3 116hy_mode(gp, cmd, data)
9acfa6cd 117 struct grf_softc *gp;
2c0f281d 118 int cmd;
6f16b9c3 119 caddr_t data;
9acfa6cd
MH
120{
121 int error = 0;
122
123 switch (cmd) {
124 case GM_GRFON:
125 case GM_GRFOFF:
126 break;
6f16b9c3
MH
127
128 /*
129 * Remember UVA of mapping for GCDESCRIBE.
130 * XXX this should be per-process.
131 */
132 case GM_MAP:
133 gp->g_data = data;
134 break;
135
136 case GM_UNMAP:
137 gp->g_data = 0;
138 break;
139
140#ifdef HPUXCOMPAT
141 case GM_DESCRIBE:
142 {
143 struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
144 struct grfinfo *gi = &gp->g_display;
57ffde05 145 int i;
6f16b9c3
MH
146
147 /* feed it what HP-UX expects */
148 fi->id = gi->gd_id;
149 fi->mapsize = gi->gd_fbsize;
150 fi->dwidth = gi->gd_dwidth;
151 fi->dlength = gi->gd_dheight;
152 fi->width = gi->gd_fbwidth;
153 fi->length = gi->gd_fbheight;
154 fi->bpp = NBBY;
155 fi->xlen = (fi->width * fi->bpp) / NBBY;
156 fi->npl = gi->gd_planes;
157 fi->bppu = fi->npl;
158 fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
159 bcopy("A1096A", fi->name, 7); /* ?? */
160 fi->attr = 0; /* ?? */
161 /*
162 * If mapped, return the UVA where mapped.
163 */
164 if (gp->g_data) {
165 fi->regbase = gp->g_data;
166 fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
167 } else {
168 fi->fbbase = 0;
169 fi->regbase = 0;
170 }
171 for (i = 0; i < 6; i++)
172 fi->regions[i] = 0;
173 break;
174 }
175#endif
176
9acfa6cd
MH
177 default:
178 error = EINVAL;
179 break;
180 }
181 return(error);
182}
183#endif