xref: /original-bsd/sys/hp300/dev/grf_hy.c (revision 95ecee29)
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.2 (Berkeley) 09/09/93
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 	caddr_t data;
93 {
94 	int error = 0;
95 
96 	switch (cmd) {
97 	case GM_GRFON:
98 	case GM_GRFOFF:
99 		break;
100 
101 	/*
102 	 * Remember UVA of mapping for GCDESCRIBE.
103 	 * XXX this should be per-process.
104 	 */
105 	case GM_MAP:
106 		gp->g_data = data;
107 		break;
108 
109 	case GM_UNMAP:
110 		gp->g_data = 0;
111 		break;
112 
113 #ifdef HPUXCOMPAT
114 	case GM_DESCRIBE:
115 	{
116 		struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
117 		struct grfinfo *gi = &gp->g_display;
118 		int i, j;
119 
120 		/* feed it what HP-UX expects */
121 		fi->id = gi->gd_id;
122 		fi->mapsize = gi->gd_fbsize;
123 		fi->dwidth = gi->gd_dwidth;
124 		fi->dlength = gi->gd_dheight;
125 		fi->width = gi->gd_fbwidth;
126 		fi->length = gi->gd_fbheight;
127 		fi->bpp = NBBY;
128 		fi->xlen = (fi->width * fi->bpp) / NBBY;
129 		fi->npl = gi->gd_planes;
130 		fi->bppu = fi->npl;
131 		fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
132 		bcopy("A1096A", fi->name, 7);	/* ?? */
133 		fi->attr = 0;			/* ?? */
134 		/*
135 		 * If mapped, return the UVA where mapped.
136 		 */
137 		if (gp->g_data) {
138 			fi->regbase = gp->g_data;
139 			fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
140 		} else {
141 			fi->fbbase = 0;
142 			fi->regbase = 0;
143 		}
144 		for (i = 0; i < 6; i++)
145 			fi->regions[i] = 0;
146 		break;
147 	}
148 #endif
149 
150 	default:
151 		error = EINVAL;
152 		break;
153 	}
154 	return(error);
155 }
156 #endif
157