gdium_genfb.c revision 1.7
11.7Sthorpej/*	$NetBSD: gdium_genfb.c,v 1.7 2023/12/20 14:12:25 thorpej 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.7Sthorpej__KERNEL_RCSID(0, "$NetBSD: gdium_genfb.c,v 1.7 2023/12/20 14:12:25 thorpej Exp $");
321.1Smatt
331.1Smatt#include <sys/param.h>
341.1Smatt#include <sys/buf.h>
351.6Smatt#include <sys/bus.h>
361.1Smatt#include <sys/conf.h>
371.1Smatt#include <sys/device.h>
381.1Smatt#include <sys/ioctl.h>
391.1Smatt#include <sys/kernel.h>
401.1Smatt#include <sys/systm.h>
411.1Smatt
421.1Smatt#include <dev/wscons/wsconsio.h>
431.1Smatt#include <dev/wscons/wsdisplayvar.h>
441.1Smatt#include <dev/rasops/rasops.h>
451.1Smatt#include <dev/wsfont/wsfont.h>
461.1Smatt#include <dev/wscons/wsdisplay_vconsvar.h>
471.1Smatt
481.1Smatt#include <mips/bonito/bonitoreg.h>
491.1Smatt#include <evbmips/gdium/gdiumvar.h>
501.1Smatt#include <dev/pci/pcireg.h>
511.1Smatt#include <dev/pci/pcivar.h>
521.1Smatt
531.1Smatt#include "wsdisplay.h"
541.1Smatt
551.1Smatt/* we need a wsdisplay to do anything halfway useful */
561.1Smatt#if NWSDISPLAY > 0
571.1Smatt
581.1Smattstatic struct vcons_screen gdium_console_screen;
591.1Smatt
601.1Smattstatic struct wsscreen_descr gdium_stdscreen = {
611.1Smatt	.name = "std",
621.1Smatt};
631.1Smatt
641.1Smattint
651.1Smattgdium_cnattach(struct gdium_config *gc)
661.1Smatt{
671.1Smatt	struct rasops_info * const ri = &gdium_console_screen.scr_ri;
681.1Smatt	long defattr;
691.1Smatt	pcireg_t reg;
701.1Smatt
711.1Smatt	wsfont_init();
721.1Smatt
731.1Smatt	/* set up rasops */
741.1Smatt	ri->ri_width = 1024;
751.1Smatt	ri->ri_height = 600;
761.1Smatt	ri->ri_depth = 16;
771.1Smatt	ri->ri_stride = 0x800;
781.3Smatt
791.1Smatt	/* read the mapping register for the frame buffer */
801.3Smatt	reg = pci_conf_read(&gc->gc_pc, pci_make_tag(&gc->gc_pc, 0, 14, 0),
811.3Smatt	    PCI_MAPREG_START);
821.3Smatt
831.1Smatt	ri->ri_bits = (char *)MIPS_PHYS_TO_KSEG1(BONITO_PCILO_BASE + reg);
841.4Smacallan	ri->ri_flg = RI_CENTER | RI_NO_AUTO;
851.1Smatt
861.2Smatt	memset(ri->ri_bits, 0, 0x200000);
871.2Smatt
881.1Smatt	/* use as much of the screen as the font permits */
891.1Smatt	rasops_init(ri, 30, 80);
901.1Smatt
911.1Smatt	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
921.1Smatt	    ri->ri_width / ri->ri_font->fontwidth);
931.1Smatt
941.1Smatt	gdium_stdscreen.nrows = ri->ri_rows;
951.1Smatt	gdium_stdscreen.ncols = ri->ri_cols;
961.1Smatt	gdium_stdscreen.textops = &ri->ri_ops;
971.1Smatt	gdium_stdscreen.capabilities = ri->ri_caps;
981.1Smatt
991.2Smatt	ri->ri_ops.allocattr(ri, 0, ri->ri_rows - 1, 0, &defattr);
1001.1Smatt
1011.1Smatt	wsdisplay_preattach(&gdium_stdscreen, ri, 0, 0, defattr);
1021.1Smatt
1031.1Smatt	return 0;
1041.1Smatt}
1051.1Smatt#else	/* NWSDISPLAY > 0 */
1061.1Smattint
1071.2Smattgdium_cnattach(struct gdium_config *gc)
1081.1Smatt{
1091.1Smatt	return -1;
1101.1Smatt}
1111.1Smatt#endif
112