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