hyper.c revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: hyper.c,v 1.1.2.2 2011/02/08 16:19:21 bouyer Exp $ */
2 1.1.2.2 bouyer /* $OpenBSD: hyper.c,v 1.15 2006/04/14 21:05:43 miod Exp $ */
3 1.1.2.2 bouyer
4 1.1.2.2 bouyer /*
5 1.1.2.2 bouyer * Copyright (c) 2005, Miodrag Vallat.
6 1.1.2.2 bouyer * All rights reserved.
7 1.1.2.2 bouyer *
8 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
10 1.1.2.2 bouyer * are met:
11 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
16 1.1.2.2 bouyer *
17 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.1.2.2 bouyer * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 1.1.2.2 bouyer * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 1.1.2.2 bouyer * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 1.1.2.2 bouyer * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.1.2.2 bouyer * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 1.1.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 1.1.2.2 bouyer * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 bouyer *
29 1.1.2.2 bouyer */
30 1.1.2.2 bouyer /*-
31 1.1.2.2 bouyer * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
32 1.1.2.2 bouyer * All rights reserved.
33 1.1.2.2 bouyer *
34 1.1.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
35 1.1.2.2 bouyer * by Jason R. Thorpe.
36 1.1.2.2 bouyer *
37 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
38 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
39 1.1.2.2 bouyer * are met:
40 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
41 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
42 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
43 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
44 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
45 1.1.2.2 bouyer *
46 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
47 1.1.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
48 1.1.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49 1.1.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
50 1.1.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 1.1.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 1.1.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 1.1.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 1.1.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 1.1.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
57 1.1.2.2 bouyer */
58 1.1.2.2 bouyer
59 1.1.2.2 bouyer /*
60 1.1.2.2 bouyer * Copyright (c) 1991 University of Utah.
61 1.1.2.2 bouyer * Copyright (c) 1990, 1993
62 1.1.2.2 bouyer * The Regents of the University of California. All rights reserved.
63 1.1.2.2 bouyer *
64 1.1.2.2 bouyer * This code is derived from software contributed to Berkeley by
65 1.1.2.2 bouyer * the Systems Programming Group of the University of Utah Computer
66 1.1.2.2 bouyer * Science Department and Mark Davies of the Department of Computer
67 1.1.2.2 bouyer * Science, Victoria University of Wellington, New Zealand.
68 1.1.2.2 bouyer *
69 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
70 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
71 1.1.2.2 bouyer * are met:
72 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
73 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
74 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
75 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
76 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
77 1.1.2.2 bouyer * 3. Neither the name of the University nor the names of its contributors
78 1.1.2.2 bouyer * may be used to endorse or promote products derived from this software
79 1.1.2.2 bouyer * without specific prior written permission.
80 1.1.2.2 bouyer *
81 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
82 1.1.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83 1.1.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84 1.1.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
85 1.1.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 1.1.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 1.1.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 1.1.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 1.1.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 1.1.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
91 1.1.2.2 bouyer * SUCH DAMAGE.
92 1.1.2.2 bouyer *
93 1.1.2.2 bouyer * from: Utah $Hdr: grf_hy.c 1.2 93/08/13$
94 1.1.2.2 bouyer *
95 1.1.2.2 bouyer * @(#)grf_hy.c 8.4 (Berkeley) 1/12/94
96 1.1.2.2 bouyer */
97 1.1.2.2 bouyer
98 1.1.2.2 bouyer /*
99 1.1.2.2 bouyer * Graphics routines for HYPERION frame buffer
100 1.1.2.2 bouyer */
101 1.1.2.2 bouyer
102 1.1.2.2 bouyer #include <sys/param.h>
103 1.1.2.2 bouyer #include <sys/systm.h>
104 1.1.2.2 bouyer #include <sys/conf.h>
105 1.1.2.2 bouyer #include <sys/device.h>
106 1.1.2.2 bouyer #include <sys/ioctl.h>
107 1.1.2.2 bouyer #include <sys/proc.h>
108 1.1.2.2 bouyer #include <sys/bus.h>
109 1.1.2.2 bouyer #include <sys/cpu.h>
110 1.1.2.2 bouyer
111 1.1.2.2 bouyer #include <machine/autoconf.h>
112 1.1.2.2 bouyer
113 1.1.2.2 bouyer #include <hp300/dev/dioreg.h>
114 1.1.2.2 bouyer #include <hp300/dev/diovar.h>
115 1.1.2.2 bouyer #include <hp300/dev/diodevs.h>
116 1.1.2.2 bouyer #include <hp300/dev/intiovar.h>
117 1.1.2.2 bouyer
118 1.1.2.2 bouyer #include <dev/wscons/wsconsio.h>
119 1.1.2.2 bouyer #include <dev/wscons/wsdisplayvar.h>
120 1.1.2.2 bouyer #include <dev/rasops/rasops.h>
121 1.1.2.2 bouyer
122 1.1.2.2 bouyer #include <hp300/dev/diofbreg.h>
123 1.1.2.2 bouyer #include <hp300/dev/diofbvar.h>
124 1.1.2.2 bouyer #include <hp300/dev/hyperreg.h>
125 1.1.2.2 bouyer
126 1.1.2.2 bouyer struct hyper_softc {
127 1.1.2.2 bouyer device_t sc_dev;
128 1.1.2.2 bouyer struct diofb *sc_fb;
129 1.1.2.2 bouyer struct diofb sc_fb_store;
130 1.1.2.2 bouyer int sc_scode;
131 1.1.2.2 bouyer };
132 1.1.2.2 bouyer
133 1.1.2.2 bouyer int hyper_match(device_t, cfdata_t, void *);
134 1.1.2.2 bouyer void hyper_attach(device_t, device_t, void *);
135 1.1.2.2 bouyer
136 1.1.2.2 bouyer CFATTACH_DECL_NEW(hyper, sizeof(struct hyper_softc),
137 1.1.2.2 bouyer hyper_match, hyper_attach, NULL, NULL);
138 1.1.2.2 bouyer
139 1.1.2.2 bouyer int hyper_reset(struct diofb *, int, struct diofbreg *);
140 1.1.2.2 bouyer
141 1.1.2.2 bouyer int hyper_ioctl(void *, void *, u_long, void *, int, struct lwp *);
142 1.1.2.2 bouyer
143 1.1.2.2 bouyer struct wsdisplay_accessops hyper_accessops = {
144 1.1.2.2 bouyer hyper_ioctl,
145 1.1.2.2 bouyer diofb_mmap,
146 1.1.2.2 bouyer diofb_alloc_screen,
147 1.1.2.2 bouyer diofb_free_screen,
148 1.1.2.2 bouyer diofb_show_screen,
149 1.1.2.2 bouyer NULL, /* load_font */
150 1.1.2.2 bouyer };
151 1.1.2.2 bouyer
152 1.1.2.2 bouyer /*
153 1.1.2.2 bouyer * Attachment glue
154 1.1.2.2 bouyer */
155 1.1.2.2 bouyer
156 1.1.2.2 bouyer int
157 1.1.2.2 bouyer hyper_match(device_t parent, cfdata_t cf, void *aux)
158 1.1.2.2 bouyer {
159 1.1.2.2 bouyer struct dio_attach_args *da = aux;
160 1.1.2.2 bouyer
161 1.1.2.2 bouyer if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER &&
162 1.1.2.2 bouyer da->da_secid == DIO_DEVICE_SECID_HYPERION)
163 1.1.2.2 bouyer return (1);
164 1.1.2.2 bouyer
165 1.1.2.2 bouyer return (0);
166 1.1.2.2 bouyer }
167 1.1.2.2 bouyer
168 1.1.2.2 bouyer void
169 1.1.2.2 bouyer hyper_attach(device_t parent, device_t self, void *aux)
170 1.1.2.2 bouyer {
171 1.1.2.2 bouyer struct hyper_softc *sc = device_private(self);
172 1.1.2.2 bouyer struct dio_attach_args *da = aux;
173 1.1.2.2 bouyer bus_space_handle_t bsh;
174 1.1.2.2 bouyer struct diofbreg *fbr;
175 1.1.2.2 bouyer
176 1.1.2.2 bouyer sc->sc_dev = self;
177 1.1.2.2 bouyer sc->sc_scode = da->da_scode;
178 1.1.2.2 bouyer if (sc->sc_scode == conscode) {
179 1.1.2.2 bouyer fbr = (struct diofbreg *)conaddr; /* already mapped */
180 1.1.2.2 bouyer sc->sc_fb = &diofb_cn;
181 1.1.2.2 bouyer } else {
182 1.1.2.2 bouyer sc->sc_fb = &sc->sc_fb_store;
183 1.1.2.2 bouyer if (bus_space_map(da->da_bst, da->da_addr, da->da_size, 0,
184 1.1.2.2 bouyer &bsh)) {
185 1.1.2.2 bouyer aprint_error(": can't map framebuffer\n");
186 1.1.2.2 bouyer return;
187 1.1.2.2 bouyer }
188 1.1.2.2 bouyer fbr = bus_space_vaddr(da->da_bst, bsh);
189 1.1.2.2 bouyer if (hyper_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
190 1.1.2.2 bouyer printf(": can't map framebuffer\n");
191 1.1.2.2 bouyer return;
192 1.1.2.2 bouyer }
193 1.1.2.2 bouyer }
194 1.1.2.2 bouyer
195 1.1.2.2 bouyer diofb_end_attach(self, &hyper_accessops, sc->sc_fb,
196 1.1.2.2 bouyer sc->sc_scode == conscode, NULL);
197 1.1.2.2 bouyer }
198 1.1.2.2 bouyer
199 1.1.2.2 bouyer /*
200 1.1.2.2 bouyer * Initialize hardware and display routines.
201 1.1.2.2 bouyer */
202 1.1.2.2 bouyer int
203 1.1.2.2 bouyer hyper_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
204 1.1.2.2 bouyer {
205 1.1.2.2 bouyer volatile struct hyboxfb *hy = (struct hyboxfb *)fbr;
206 1.1.2.2 bouyer int rc;
207 1.1.2.2 bouyer
208 1.1.2.2 bouyer if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
209 1.1.2.2 bouyer return (rc);
210 1.1.2.2 bouyer
211 1.1.2.2 bouyer fb->bmv = diofb_mono_windowmove;
212 1.1.2.2 bouyer
213 1.1.2.2 bouyer fb->ri.ri_depth = 1; /* do not fake a 8bpp frame buffer */
214 1.1.2.2 bouyer diofb_fbsetup(fb);
215 1.1.2.2 bouyer
216 1.1.2.2 bouyer /* enable display */
217 1.1.2.2 bouyer hy->nblank = DISP_VIDEO_ENABLE | DISP_SYNC_ENABLE;
218 1.1.2.2 bouyer
219 1.1.2.2 bouyer return (0);
220 1.1.2.2 bouyer }
221 1.1.2.2 bouyer
222 1.1.2.2 bouyer int
223 1.1.2.2 bouyer hyper_ioctl(void *v, void *vs, u_long cmd, void *data, int flags, struct lwp *l)
224 1.1.2.2 bouyer {
225 1.1.2.2 bouyer struct diofb *fb = v;
226 1.1.2.2 bouyer struct wsdisplay_fbinfo *wdf;
227 1.1.2.2 bouyer
228 1.1.2.2 bouyer switch (cmd) {
229 1.1.2.2 bouyer case WSDISPLAYIO_GTYPE:
230 1.1.2.2 bouyer *(u_int *)data = WSDISPLAY_TYPE_HYPERION;
231 1.1.2.2 bouyer return 0;
232 1.1.2.2 bouyer case WSDISPLAYIO_SMODE:
233 1.1.2.2 bouyer fb->mapmode = *(u_int *)data;
234 1.1.2.2 bouyer return 0;
235 1.1.2.2 bouyer case WSDISPLAYIO_GINFO:
236 1.1.2.2 bouyer wdf = (void *)data;
237 1.1.2.2 bouyer wdf->width = fb->ri.ri_width;
238 1.1.2.2 bouyer wdf->height = fb->ri.ri_height;
239 1.1.2.2 bouyer wdf->depth = fb->ri.ri_depth;
240 1.1.2.2 bouyer wdf->cmsize = 0;
241 1.1.2.2 bouyer return 0;
242 1.1.2.2 bouyer case WSDISPLAYIO_LINEBYTES:
243 1.1.2.2 bouyer *(u_int *)data = fb->ri.ri_stride;
244 1.1.2.2 bouyer return 0;
245 1.1.2.2 bouyer case WSDISPLAYIO_GVIDEO:
246 1.1.2.2 bouyer case WSDISPLAYIO_SVIDEO:
247 1.1.2.2 bouyer return EPASSTHROUGH;
248 1.1.2.2 bouyer case WSDISPLAYIO_GETCMAP:
249 1.1.2.2 bouyer case WSDISPLAYIO_PUTCMAP:
250 1.1.2.2 bouyer return EPASSTHROUGH;
251 1.1.2.2 bouyer }
252 1.1.2.2 bouyer
253 1.1.2.2 bouyer return EPASSTHROUGH;
254 1.1.2.2 bouyer }
255 1.1.2.2 bouyer
256 1.1.2.2 bouyer /*
257 1.1.2.2 bouyer * Hyperion console support
258 1.1.2.2 bouyer */
259 1.1.2.2 bouyer
260 1.1.2.2 bouyer int
261 1.1.2.2 bouyer hypercnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
262 1.1.2.2 bouyer {
263 1.1.2.2 bouyer bus_space_handle_t bsh;
264 1.1.2.2 bouyer void *va;
265 1.1.2.2 bouyer struct diofbreg *fbr;
266 1.1.2.2 bouyer struct diofb *fb = &diofb_cn;
267 1.1.2.2 bouyer int size;
268 1.1.2.2 bouyer
269 1.1.2.2 bouyer if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
270 1.1.2.2 bouyer return 1;
271 1.1.2.2 bouyer va = bus_space_vaddr(bst, bsh);
272 1.1.2.2 bouyer fbr = va;
273 1.1.2.2 bouyer
274 1.1.2.2 bouyer if (badaddr(va) ||
275 1.1.2.2 bouyer (fbr->id != GRFHWID) || (fbr->fbid != GID_HYPERION)) {
276 1.1.2.2 bouyer bus_space_unmap(bst, bsh, PAGE_SIZE);
277 1.1.2.2 bouyer return 1;
278 1.1.2.2 bouyer }
279 1.1.2.2 bouyer
280 1.1.2.2 bouyer size = DIO_SIZE(scode, va);
281 1.1.2.2 bouyer
282 1.1.2.2 bouyer bus_space_unmap(bst, bsh, PAGE_SIZE);
283 1.1.2.2 bouyer if (bus_space_map(bst, addr, size, 0, &bsh))
284 1.1.2.2 bouyer return 1;
285 1.1.2.2 bouyer va = bus_space_vaddr(bst, bsh);
286 1.1.2.2 bouyer
287 1.1.2.2 bouyer /*
288 1.1.2.2 bouyer * Initialize the framebuffer hardware.
289 1.1.2.2 bouyer */
290 1.1.2.2 bouyer conscode = scode;
291 1.1.2.2 bouyer conaddr = va;
292 1.1.2.2 bouyer hyper_reset(fb, conscode, (struct diofbreg *)conaddr);
293 1.1.2.2 bouyer
294 1.1.2.2 bouyer /*
295 1.1.2.2 bouyer * Initialize the terminal emulator.
296 1.1.2.2 bouyer */
297 1.1.2.2 bouyer diofb_cnattach(fb);
298 1.1.2.2 bouyer return 0;
299 1.1.2.2 bouyer }
300