gdium_genfb.c revision 1.7
1/*	$NetBSD: gdium_genfb.c,v 1.7 2023/12/20 14:12:25 thorpej 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.7 2023/12/20 14:12:25 thorpej 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/systm.h>
41
42#include <dev/wscons/wsconsio.h>
43#include <dev/wscons/wsdisplayvar.h>
44#include <dev/rasops/rasops.h>
45#include <dev/wsfont/wsfont.h>
46#include <dev/wscons/wsdisplay_vconsvar.h>
47
48#include <mips/bonito/bonitoreg.h>
49#include <evbmips/gdium/gdiumvar.h>
50#include <dev/pci/pcireg.h>
51#include <dev/pci/pcivar.h>
52
53#include "wsdisplay.h"
54
55/* we need a wsdisplay to do anything halfway useful */
56#if NWSDISPLAY > 0
57
58static struct vcons_screen gdium_console_screen;
59
60static struct wsscreen_descr gdium_stdscreen = {
61	.name = "std",
62};
63
64int
65gdium_cnattach(struct gdium_config *gc)
66{
67	struct rasops_info * const ri = &gdium_console_screen.scr_ri;
68	long defattr;
69	pcireg_t reg;
70
71	wsfont_init();
72
73	/* set up rasops */
74	ri->ri_width = 1024;
75	ri->ri_height = 600;
76	ri->ri_depth = 16;
77	ri->ri_stride = 0x800;
78
79	/* read the mapping register for the frame buffer */
80	reg = pci_conf_read(&gc->gc_pc, pci_make_tag(&gc->gc_pc, 0, 14, 0),
81	    PCI_MAPREG_START);
82
83	ri->ri_bits = (char *)MIPS_PHYS_TO_KSEG1(BONITO_PCILO_BASE + reg);
84	ri->ri_flg = RI_CENTER | RI_NO_AUTO;
85
86	memset(ri->ri_bits, 0, 0x200000);
87
88	/* use as much of the screen as the font permits */
89	rasops_init(ri, 30, 80);
90
91	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
92	    ri->ri_width / ri->ri_font->fontwidth);
93
94	gdium_stdscreen.nrows = ri->ri_rows;
95	gdium_stdscreen.ncols = ri->ri_cols;
96	gdium_stdscreen.textops = &ri->ri_ops;
97	gdium_stdscreen.capabilities = ri->ri_caps;
98
99	ri->ri_ops.allocattr(ri, 0, ri->ri_rows - 1, 0, &defattr);
100
101	wsdisplay_preattach(&gdium_stdscreen, ri, 0, 0, defattr);
102
103	return 0;
104}
105#else	/* NWSDISPLAY > 0 */
106int
107gdium_cnattach(struct gdium_config *gc)
108{
109	return -1;
110}
111#endif
112