gdium_genfb.c revision 1.3
11.3Smatt/*	$NetBSD: gdium_genfb.c,v 1.3 2009/08/08 20:48:33 matt Exp $	*/
21.1Smatt
31.1Smatt/*
41.1Smatt * Copyright (c) 1995, 1996 Carnegie-Mellon University.
51.1Smatt * All rights reserved.
61.1Smatt *
71.1Smatt * Author: Chris G. Demetriou
81.1Smatt *
91.1Smatt * Permission to use, copy, modify and distribute this software and
101.1Smatt * its documentation is hereby granted, provided that both the copyright
111.1Smatt * notice and this permission notice appear in all copies of the
121.1Smatt * software, derivative works or modified versions, and any portions
131.1Smatt * thereof, and that both notices appear in supporting documentation.
141.1Smatt *
151.1Smatt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
161.1Smatt * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
171.1Smatt * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
181.1Smatt *
191.1Smatt * Carnegie Mellon requests users of this software to return to
201.1Smatt *
211.1Smatt *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
221.1Smatt *  School of Computer Science
231.1Smatt *  Carnegie Mellon University
241.1Smatt *  Pittsburgh PA 15213-3890
251.1Smatt *
261.1Smatt * any improvements or extensions that they make and grant Carnegie the
271.1Smatt * rights to redistribute these changes.
281.1Smatt */
291.1Smatt
301.1Smatt#include <sys/cdefs.h>
311.3Smatt__KERNEL_RCSID(0, "$NetBSD: gdium_genfb.c,v 1.3 2009/08/08 20:48:33 matt Exp $");
321.1Smatt
331.1Smatt#include <sys/param.h>
341.1Smatt#include <sys/buf.h>
351.1Smatt#include <sys/conf.h>
361.1Smatt#include <sys/device.h>
371.1Smatt#include <sys/ioctl.h>
381.1Smatt#include <sys/kernel.h>
391.1Smatt#include <sys/malloc.h>
401.1Smatt#include <sys/systm.h>
411.1Smatt
421.1Smatt#include <machine/bus.h>
431.1Smatt
441.1Smatt#include <dev/wscons/wsconsio.h>
451.1Smatt#include <dev/wscons/wsdisplayvar.h>
461.1Smatt#include <dev/rasops/rasops.h>
471.1Smatt#include <dev/wsfont/wsfont.h>
481.1Smatt#include <dev/wscons/wsdisplay_vconsvar.h>
491.1Smatt
501.1Smatt#include <mips/bonito/bonitoreg.h>
511.1Smatt#include <evbmips/gdium/gdiumvar.h>
521.1Smatt#include <dev/pci/pcireg.h>
531.1Smatt#include <dev/pci/pcivar.h>
541.1Smatt
551.1Smatt#include "wsdisplay.h"
561.1Smatt
571.1Smatt/* we need a wsdisplay to do anything halfway useful */
581.1Smatt#if NWSDISPLAY > 0
591.1Smatt
601.1Smattstatic struct vcons_screen gdium_console_screen;
611.1Smatt
621.1Smattstatic struct wsscreen_descr gdium_stdscreen = {
631.1Smatt	.name = "std",
641.1Smatt};
651.1Smatt
661.1Smattint
671.1Smattgdium_cnattach(struct gdium_config *gc)
681.1Smatt{
691.1Smatt	struct rasops_info * const ri = &gdium_console_screen.scr_ri;
701.1Smatt	long defattr;
711.1Smatt	pcireg_t reg;
721.1Smatt
731.1Smatt	wsfont_init();
741.1Smatt
751.1Smatt	/* set up rasops */
761.1Smatt	ri->ri_width = 1024;
771.1Smatt	ri->ri_height = 600;
781.1Smatt	ri->ri_depth = 16;
791.1Smatt	ri->ri_stride = 0x800;
801.3Smatt
811.1Smatt	/* read the mapping register for the frame buffer */
821.3Smatt	reg = pci_conf_read(&gc->gc_pc, pci_make_tag(&gc->gc_pc, 0, 14, 0),
831.3Smatt	    PCI_MAPREG_START);
841.3Smatt
851.1Smatt	ri->ri_bits = (char *)MIPS_PHYS_TO_KSEG1(BONITO_PCILO_BASE + reg);
861.3Smatt	ri->ri_flg = RI_CENTER;
871.1Smatt
881.2Smatt	memset(ri->ri_bits, 0, 0x200000);
891.2Smatt
901.1Smatt	/* use as much of the screen as the font permits */
911.1Smatt	rasops_init(ri, 30, 80);
921.1Smatt
931.1Smatt	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
941.1Smatt	    ri->ri_width / ri->ri_font->fontwidth);
951.1Smatt
961.1Smatt	gdium_stdscreen.nrows = ri->ri_rows;
971.1Smatt	gdium_stdscreen.ncols = ri->ri_cols;
981.1Smatt	gdium_stdscreen.textops = &ri->ri_ops;
991.1Smatt	gdium_stdscreen.capabilities = ri->ri_caps;
1001.1Smatt
1011.2Smatt	ri->ri_ops.allocattr(ri, 0, ri->ri_rows - 1, 0, &defattr);
1021.1Smatt
1031.1Smatt	wsdisplay_preattach(&gdium_stdscreen, ri, 0, 0, defattr);
1041.1Smatt
1051.1Smatt	return 0;
1061.1Smatt}
1071.1Smatt#else	/* NWSDISPLAY > 0 */
1081.1Smattint
1091.2Smattgdium_cnattach(struct gdium_config *gc)
1101.1Smatt{
1111.1Smatt	return -1;
1121.1Smatt}
1131.1Smatt#endif
114