xref: /netbsd-src/sys/arch/evbmips/gdium/gdium_genfb.c (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: gdium_genfb.c,v 1.6 2011/07/10 00:03:53 matt Exp $	*/
2 
3 /*
4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Chris G. Demetriou
8  *
9  * Permission to use, copy, modify and distribute this software and
10  * its documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  */
29 
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: gdium_genfb.c,v 1.6 2011/07/10 00:03:53 matt Exp $");
32 
33 #include <sys/param.h>
34 #include <sys/buf.h>
35 #include <sys/bus.h>
36 #include <sys/conf.h>
37 #include <sys/device.h>
38 #include <sys/ioctl.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/systm.h>
42 
43 #include <dev/wscons/wsconsio.h>
44 #include <dev/wscons/wsdisplayvar.h>
45 #include <dev/rasops/rasops.h>
46 #include <dev/wsfont/wsfont.h>
47 #include <dev/wscons/wsdisplay_vconsvar.h>
48 
49 #include <mips/bonito/bonitoreg.h>
50 #include <evbmips/gdium/gdiumvar.h>
51 #include <dev/pci/pcireg.h>
52 #include <dev/pci/pcivar.h>
53 
54 #include "wsdisplay.h"
55 
56 /* we need a wsdisplay to do anything halfway useful */
57 #if NWSDISPLAY > 0
58 
59 static struct vcons_screen gdium_console_screen;
60 
61 static struct wsscreen_descr gdium_stdscreen = {
62 	.name = "std",
63 };
64 
65 int
66 gdium_cnattach(struct gdium_config *gc)
67 {
68 	struct rasops_info * const ri = &gdium_console_screen.scr_ri;
69 	long defattr;
70 	pcireg_t reg;
71 
72 	wsfont_init();
73 
74 	/* set up rasops */
75 	ri->ri_width = 1024;
76 	ri->ri_height = 600;
77 	ri->ri_depth = 16;
78 	ri->ri_stride = 0x800;
79 
80 	/* read the mapping register for the frame buffer */
81 	reg = pci_conf_read(&gc->gc_pc, pci_make_tag(&gc->gc_pc, 0, 14, 0),
82 	    PCI_MAPREG_START);
83 
84 	ri->ri_bits = (char *)MIPS_PHYS_TO_KSEG1(BONITO_PCILO_BASE + reg);
85 	ri->ri_flg = RI_CENTER | RI_NO_AUTO;
86 
87 	memset(ri->ri_bits, 0, 0x200000);
88 
89 	/* use as much of the screen as the font permits */
90 	rasops_init(ri, 30, 80);
91 
92 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
93 	    ri->ri_width / ri->ri_font->fontwidth);
94 
95 	gdium_stdscreen.nrows = ri->ri_rows;
96 	gdium_stdscreen.ncols = ri->ri_cols;
97 	gdium_stdscreen.textops = &ri->ri_ops;
98 	gdium_stdscreen.capabilities = ri->ri_caps;
99 
100 	ri->ri_ops.allocattr(ri, 0, ri->ri_rows - 1, 0, &defattr);
101 
102 	wsdisplay_preattach(&gdium_stdscreen, ri, 0, 0, defattr);
103 
104 	return 0;
105 }
106 #else	/* NWSDISPLAY > 0 */
107 int
108 gdium_cnattach(struct gdium_config *gc)
109 {
110 	return -1;
111 }
112 #endif
113