xref: /netbsd/sys/arch/x86/x86/genfb_machdep.c (revision 6550d01e)
1 /* $NetBSD: genfb_machdep.c,v 1.4 2010/04/28 19:17:04 dyoung Exp $ */
2 
3 /*-
4  * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * Early attach support for raster consoles
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: genfb_machdep.c,v 1.4 2010/04/28 19:17:04 dyoung Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/conf.h>
38 #include <sys/device.h>
39 #include <sys/ioctl.h>
40 #include <sys/kernel.h>
41 
42 #include <machine/bus.h>
43 #include <machine/bootinfo.h>
44 
45 #include <dev/wscons/wsconsio.h>
46 #include <dev/wscons/wsdisplayvar.h>
47 #include <dev/rasops/rasops.h>
48 #include <dev/wsfont/wsfont.h>
49 #include <dev/wscons/wsdisplay_vconsvar.h>
50 
51 #include <arch/x86/include/genfb_machdep.h>
52 
53 #include "wsdisplay.h"
54 #include "genfb.h"
55 #include "acpica.h"
56 
57 #if NWSDISPLAY > 0 && NGENFB > 0
58 struct vcons_screen x86_genfb_console_screen;
59 
60 #if NACPICA > 0
61 extern int acpi_md_vesa_modenum;
62 #endif
63 
64 static struct wsscreen_descr x86_genfb_stdscreen = {
65 	"std",
66 	0, 0,
67 	0,
68 	0, 0,
69 	0,
70 	NULL
71 };
72 
73 int
74 x86_genfb_cnattach(void)
75 {
76 	static int ncalls = 0;
77 	struct rasops_info *ri = &x86_genfb_console_screen.scr_ri;
78 	const struct btinfo_framebuffer *fbinfo;
79 	bus_space_tag_t t = x86_bus_space_mem;
80 	bus_space_handle_t h;
81 	void *bits;
82 	long defattr;
83 	int err;
84 
85 	/* XXX jmcneill
86 	 *  Defer console initialization until UVM is initialized
87 	 */
88 	++ncalls;
89 	if (ncalls < 3)
90 		return -1;
91 
92 	memset(&x86_genfb_console_screen, 0, sizeof(x86_genfb_console_screen));
93 
94 	fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER);
95 	if (fbinfo == NULL || fbinfo->physaddr == 0)
96 		return 0;
97 
98 	err = _x86_memio_map(t, (bus_addr_t)fbinfo->physaddr,
99 	    fbinfo->width * fbinfo->stride,
100 	    BUS_SPACE_MAP_LINEAR, &h);
101 	if (err) {
102 		aprint_error("x86_genfb_cnattach: couldn't map framebuffer\n");
103 		return 0;
104 	}
105 
106 	bits = bus_space_vaddr(t, h);
107 	if (bits == NULL) {
108 		aprint_error("x86_genfb_cnattach: couldn't get fb vaddr\n");
109 		return 0;
110 	}
111 
112 #if NACPICA > 0
113 	acpi_md_vesa_modenum = fbinfo->vbemode;
114 #endif
115 
116 	wsfont_init();
117 
118 	ri->ri_width = fbinfo->width;
119 	ri->ri_height = fbinfo->height;
120 	ri->ri_depth = fbinfo->depth;
121 	ri->ri_stride = fbinfo->stride;
122 	ri->ri_bits = bits;
123 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR | RI_CLEAR;
124 	rasops_init(ri, ri->ri_width / 8, ri->ri_height / 8);
125 	ri->ri_caps = WSSCREEN_WSCOLORS;
126 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
127 	    ri->ri_width / ri->ri_font->fontwidth);
128 
129 	x86_genfb_stdscreen.nrows = ri->ri_rows;
130 	x86_genfb_stdscreen.ncols = ri->ri_cols;
131 	x86_genfb_stdscreen.textops = &ri->ri_ops;
132 	x86_genfb_stdscreen.capabilities = ri->ri_caps;
133 
134 	ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr);
135 	wsdisplay_preattach(&x86_genfb_stdscreen, ri, 0, 0, defattr);
136 
137 	return 1;
138 }
139 #else	/* NWSDISPLAY > 0 && NGENFB > 0 */
140 int
141 x86_genfb_cnattach(void)
142 {
143 	return 0;
144 }
145 #endif
146