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