xref: /original-bsd/sys/hp300/dev/grf_hy.c (revision 7a38d872)
1 /*
2  * Copyright (c) 1991 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 and Mark Davies of the Department of Computer
9  * Science, Victoria University of Wellington, New Zealand.
10  *
11  * %sccs.include.redist.c%
12  *
13  * from: Utah $Hdr: grf_hy.c 1.2 93/08/13$
14  *
15  *	@(#)grf_hy.c	8.4 (Berkeley) 01/12/94
16  */
17 
18 #include "grf.h"
19 #if NGRF > 0
20 
21 /*
22  * Graphics routines for HYPERION frame buffer
23  */
24 #include <sys/param.h>
25 #include <sys/errno.h>
26 
27 #include <hp/dev/grfioctl.h>
28 #include <hp/dev/grfvar.h>
29 #include <hp300/dev/grf_hyreg.h>
30 
31 #include <machine/cpu.h>
32 
33 caddr_t badhyaddr = (caddr_t) -1;
34 
35 /*
36  * Initialize hardware.
37  * Must fill in the grfinfo structure in g_softc.
38  * Returns 0 if hardware not present, non-zero ow.
39  */
40 hy_init(gp, addr)
41 	struct grf_softc *gp;
42 	caddr_t addr;
43 {
44 	register struct hyboxfb *hy = (struct hyboxfb *) addr;
45 	struct grfinfo *gi = &gp->g_display;
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 = 0x20000;
54 	gi->gd_fbwidth = (hy->fbwmsb << 8) | hy->fbwlsb;
55 	gi->gd_fbheight = (hy->fbhmsb << 8) | hy->fbhlsb;
56 	gi->gd_fbsize = (gi->gd_fbwidth * gi->gd_fbheight) >> 3;
57 	fboff = (hy->fbomsb << 8) | hy->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 = (hy->dwmsb << 8) | hy->dwlsb;
77 	gi->gd_dheight = (hy->dhmsb << 8) | hy->dhlsb;
78 	gi->gd_planes = hy->num_planes;
79 	gi->gd_colors = 1 << gi->gd_planes;
80 
81 	return(1);
82 }
83 
84 /*
85  * Change the mode of the display.
86  * Right now all we can do is grfon/grfoff.
87  * Return a UNIX error number or 0 for success.
88  * Function may not be needed anymore.
89  */
90 hy_mode(gp, cmd, data)
91 	struct grf_softc *gp;
92 	int cmd;
93 	caddr_t data;
94 {
95 	int error = 0;
96 
97 	switch (cmd) {
98 	case GM_GRFON:
99 	case GM_GRFOFF:
100 		break;
101 
102 	/*
103 	 * Remember UVA of mapping for GCDESCRIBE.
104 	 * XXX this should be per-process.
105 	 */
106 	case GM_MAP:
107 		gp->g_data = data;
108 		break;
109 
110 	case GM_UNMAP:
111 		gp->g_data = 0;
112 		break;
113 
114 #ifdef HPUXCOMPAT
115 	case GM_DESCRIBE:
116 	{
117 		struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
118 		struct grfinfo *gi = &gp->g_display;
119 		int i;
120 
121 		/* feed it what HP-UX expects */
122 		fi->id = gi->gd_id;
123 		fi->mapsize = gi->gd_fbsize;
124 		fi->dwidth = gi->gd_dwidth;
125 		fi->dlength = gi->gd_dheight;
126 		fi->width = gi->gd_fbwidth;
127 		fi->length = gi->gd_fbheight;
128 		fi->bpp = NBBY;
129 		fi->xlen = (fi->width * fi->bpp) / NBBY;
130 		fi->npl = gi->gd_planes;
131 		fi->bppu = fi->npl;
132 		fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
133 		bcopy("A1096A", fi->name, 7);	/* ?? */
134 		fi->attr = 0;			/* ?? */
135 		/*
136 		 * If mapped, return the UVA where mapped.
137 		 */
138 		if (gp->g_data) {
139 			fi->regbase = gp->g_data;
140 			fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
141 		} else {
142 			fi->fbbase = 0;
143 			fi->regbase = 0;
144 		}
145 		for (i = 0; i < 6; i++)
146 			fi->regions[i] = 0;
147 		break;
148 	}
149 #endif
150 
151 	default:
152 		error = EINVAL;
153 		break;
154 	}
155 	return(error);
156 }
157 #endif
158