Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jan 2014 17:42:07 +0200
From:      Aleksandr Rybalko <ray@freebsd.org>
To:        current@freebsd.org
Subject:   [CFT] updated ofwfb driver vt(9)
Message-ID:  <20140117174207.88bedb221f2ac942c607dbf1@freebsd.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

--Multipart=_Fri__17_Jan_2014_17_42_07_+0200_naE5YrvJnuCVT7_H
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Hello hackers!

I did updated version of vt's ofwfb driver, but have no HW to test.
It will be very nice if someone try it on ppc/sparc device.

Instructions on how to enable vt(9) (newcons) can be found here:
https://wiki.freebsd.org/Newcons

Patch to HEAD in attachment. (hope it will not be stripped)

xf86-video-scfb expected to work too :)

Many-many thanks!

WBW
-- 
Aleksandr Rybalko <ray@freebsd.org>

--Multipart=_Fri__17_Jan_2014_17_42_07_+0200_naE5YrvJnuCVT7_H
Content-Type: text/x-diff;
 name="ofwfb.update.patch"
Content-Disposition: attachment;
 filename="ofwfb.update.patch"
Content-Transfer-Encoding: 7bit

Index: ofwfb.c
===================================================================
--- ofwfb.c	(revision 260753)
+++ ofwfb.c	(working copy)
@@ -30,8 +30,10 @@
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/systm.h>
+#include <sys/fbio.h>
 
 #include <dev/vt/vt.h>
+#include <dev/vt/hw/fb/vt_fb.h>
 #include <dev/vt/colors/vt_termcolors.h>
 
 #include <vm/vm.h>
@@ -47,25 +49,19 @@
 #include <dev/ofw/ofw_pci.h>
 
 struct ofwfb_softc {
+	struct fb_info	info;
+
+	/* Own variables. */
 	phandle_t	sc_node;
-
-	intptr_t	sc_addr;
-	int		sc_depth;
-	int		sc_stride;
-
-	bus_space_tag_t	sc_memt; 
-
-	uint32_t	sc_colormap[16];
+	bus_space_tag_t	sc_memt;
 };
 
 static vd_init_t	ofwfb_init;
-static vd_blank_t	ofwfb_blank;
-static vd_bitbltchr_t	ofwfb_bitbltchr;
 
 static const struct vt_driver vt_ofwfb_driver = {
 	.vd_init	= ofwfb_init,
-	.vd_blank	= ofwfb_blank,
-	.vd_bitbltchr	= ofwfb_bitbltchr,
+	.vd_blank	= vt_fb_blank,
+	.vd_bitbltchr	= vt_fb_bitbltchr,
 	.vd_priority	= VD_PRIORITY_GENERIC+1,
 };
 
@@ -75,86 +71,8 @@
 /* XXX: hardcoded max size */
 
 static void
-ofwfb_blank(struct vt_device *vd, term_color_t color)
+ofwfb_initialize(struct ofwfb_softc *sc)
 {
-	struct ofwfb_softc *sc = vd->vd_softc;
-	u_int ofs;
-	uint32_t c;
-
-	switch (sc->sc_depth) {
-	case 8:
-		for (ofs = 0; ofs < sc->sc_stride*vd->vd_height; ofs++)
-			*(uint8_t *)(sc->sc_addr + ofs) = color;
-		break;
-	case 32:
-		c = sc->sc_colormap[color];
-		for (ofs = 0; ofs < sc->sc_stride*vd->vd_height; ofs++)
-			*(uint32_t *)(sc->sc_addr + 4*ofs) = c;
-		break;
-	default:
-		/* panic? */
-		break;
-	}
-}
-
-static void
-ofwfb_bitbltchr(struct vt_device *vd, const uint8_t *src, const uint8_t *mask,
-    int bpl, vt_axis_t top, vt_axis_t left, unsigned int width,
-    unsigned int height, term_color_t fg, term_color_t bg)
-{
-	struct ofwfb_softc *sc = vd->vd_softc;
-	u_long line;
-	uint32_t fgc, bgc;
-	int c;
-	uint8_t b, m;
-
-	fgc = sc->sc_colormap[fg];
-	bgc = sc->sc_colormap[bg];
-	b = m = 0;
-
-	/* Don't try to put off screen pixels */
-	if (((left + width) > vd->vd_width) || ((top + height) >
-	    vd->vd_height))
-		return;
-
-	line = (sc->sc_stride * top) + left * sc->sc_depth/8;
-	for (; height > 0; height--) {
-		for (c = 0; c < width; c++) {
-			if (c % 8 == 0)
-				b = *src++;
-			else
-				b <<= 1;
-			if (mask != NULL) {
-				if (c % 8 == 0)
-					m = *mask++;
-				else
-					m <<= 1;
-				/* Skip pixel write, if mask has no bit set. */
-				if ((m & 0x80) == 0)
-					continue;
-			}
-			switch(sc->sc_depth) {
-			case 8:
-				*(uint8_t *)(sc->sc_addr + line + c) =
-				    b & 0x80 ? fg : bg;
-				break;
-			case 32:
-				*(uint32_t *)(sc->sc_addr + line + 4*c) = 
-				    (b & 0x80) ? fgc : bgc;
-				break;
-			default:
-				/* panic? */
-				break;
-			}
-		}
-		line += sc->sc_stride;
-	}
-}
-
-static void
-ofwfb_initialize(struct vt_device *vd)
-{
-	struct ofwfb_softc *sc = vd->vd_softc;
 	char name[64];
 	ihandle_t ih;
 	int i;
@@ -170,16 +88,16 @@
 	 * Set up the color map
 	 */
 
-	switch (sc->sc_depth) {
+	switch (sc->info.fb_bpp) {
 	case 8:
-		vt_generate_vga_palette(sc->sc_colormap, COLOR_FORMAT_RGB, 255,
+		vt_generate_vga_palette(sc->info.fb_cmap, COLOR_FORMAT_RGB, 255,
 		    0, 255, 8, 255, 16);
 
 		for (i = 0; i < 16; i++) {
 			OF_call_method("color!", ih, 4, 1,
-			    (cell_t)((sc->sc_colormap[i] >> 16) & 0xff),
-			    (cell_t)((sc->sc_colormap[i] >> 8) & 0xff),
-			    (cell_t)((sc->sc_colormap[i] >> 0) & 0xff),
+			    (cell_t)((sc->info.fb_cmap[i] >> 16) & 0xff),
+			    (cell_t)((sc->info.fb_cmap[i] >> 8) & 0xff),
+			    (cell_t)((sc->info.fb_cmap[i] >> 0) & 0xff),
 			    (cell_t)i, &retval);
 		}
 		break;
@@ -192,24 +110,22 @@
 		 * endianness slightly different. Figure out the host-view
 		 * endianness of the frame buffer.
 		 */
-		oldpix = bus_space_read_4(sc->sc_memt, sc->sc_addr, 0);
-		bus_space_write_4(sc->sc_memt, sc->sc_addr, 0, 0xff000000);
-		if (*(uint8_t *)(sc->sc_addr) == 0xff)
-			vt_generate_vga_palette(sc->sc_colormap,
+		oldpix = bus_space_read_4(sc->sc_memt, sc->info.fb_vbase, 0);
+		bus_space_write_4(sc->sc_memt, sc->info.fb_vbase, 0, 0xff000000);
+		if (*(uint8_t *)(sc->info.fb_vbase) == 0xff)
+			vt_generate_vga_palette(sc->info.fb_cmap,
 			    COLOR_FORMAT_RGB, 255, 16, 255, 8, 255, 0);
 		else
-			vt_generate_vga_palette(sc->sc_colormap,
+			vt_generate_vga_palette(sc->info.fb_cmap,
 			    COLOR_FORMAT_RGB, 255, 0, 255, 8, 255, 16);
-		bus_space_write_4(sc->sc_memt, sc->sc_addr, 0, oldpix);
+		bus_space_write_4(sc->sc_memt, sc->info.fb_vbase, 0, oldpix);
 		break;
 
 	default:
-		panic("Unknown color space depth %d", sc->sc_depth);
+		panic("Unknown color space depth %d", sc->info.fb_bpp);
 		break;
         }
 
-	/* Clear the screen. */
-	ofwfb_blank(vd, TC_BLACK);
 }
 
 static int
@@ -252,7 +168,7 @@
 	if (OF_getproplen(node, "height") != sizeof(height) ||
 	    OF_getproplen(node, "width") != sizeof(width) ||
 	    OF_getproplen(node, "depth") != sizeof(depth) ||
-	    OF_getproplen(node, "linebytes") != sizeof(sc->sc_stride))
+	    OF_getproplen(node, "linebytes") != sizeof(sc->info.fb_stride))
 		return (CN_DEAD);
 
 	/* Only support 8 and 32-bit framebuffers */
@@ -259,14 +175,15 @@
 	OF_getprop(node, "depth", &depth, sizeof(depth));
 	if (depth != 8 && depth != 32)
 		return (CN_DEAD);
-	sc->sc_depth = depth;
+	sc->info.fb_bpp = depth;
+	sc->info.fb_depth = (depth == 32) ? 24 : 8;
 
 	OF_getprop(node, "height", &height, sizeof(height));
 	OF_getprop(node, "width", &width, sizeof(width));
-	OF_getprop(node, "linebytes", &sc->sc_stride, sizeof(sc->sc_stride));
+	OF_getprop(node, "linebytes", &sc->info.fb_stride, sizeof(sc->info.fb_stride));
 
-	vd->vd_height = height;
-	vd->vd_width = width;
+	sc->info.fb_height = height;
+	sc->info.fb_width = width;
 
 	/*
 	 * Get the PCI addresses of the adapter, if present. The node may be the
@@ -294,12 +211,14 @@
 
 	#if defined(__powerpc__)
 		sc->sc_memt = &bs_be_tag;
-		bus_space_map(sc->sc_memt, fb_phys, height * sc->sc_stride,
-		    BUS_SPACE_MAP_PREFETCHABLE, &sc->sc_addr);
+		bus_space_map(sc->sc_memt, fb_phys, height * sc->info.fb_stride,
+		    BUS_SPACE_MAP_PREFETCHABLE, &sc->info.fb_vbase);
+		sc->info.fb_pbase = fb_phys;
 	#elif defined(__sparc64__)
 		OF_decode_addr(node, 0, &space, &phys);
 		sc->sc_memt = &ofwfb_memt[0];
-		sc->sc_addr = sparc64_fake_bustag(space, fb_phys, sc->sc_memt);
+		sc->info.fb_vbase = sparc64_fake_bustag(space, fb_phys, sc->sc_memt);
+		sc->info.fb_pbase = fb_phys;
 	#else
 		#error Unsupported platform!
 	#endif
@@ -314,7 +233,7 @@
 		fb_phys = n_pciaddrs;
 		for (i = 0; i < n_pciaddrs; i++) {
 			/* If it is too small, not the framebuffer */
-			if (pciaddrs[i].size_lo < sc->sc_stride*height)
+			if (pciaddrs[i].size_lo < sc->info.fb_stride*height)
 				continue;
 			/* If it is not memory, it isn't either */
 			if (!(pciaddrs[i].phys_hi &
@@ -333,16 +252,23 @@
 			return (CN_DEAD);
 
 	#if defined(__powerpc__)
-		OF_decode_addr(node, fb_phys, &sc->sc_memt, &sc->sc_addr);
+		OF_decode_addr(node, fb_phys, &sc->sc_memt, &sc->info.fb_vbase);
+		sc->info.fb_pbase = fb_phys;
 	#elif defined(__sparc64__)
 		OF_decode_addr(node, fb_phys, &space, &phys);
 		sc->sc_memt = &ofwfb_memt[0];
-		sc->sc_addr = sparc64_fake_bustag(space, phys, sc->sc_memt);
+		sc->info.fb_vbase = sparc64_fake_bustag(space, phys, sc->sc_memt);
+		sc->info.fb_pbase = fb_phys;
 	#endif
         }
 
-	ofwfb_initialize(vd);
+	ofwfb_initialize(sc);
 
+	/* Initialize fb_info. */
+	sc->info.fb_size = height * width * depth / 4;
+
+	fb_probe(&sc->info);
+	vt_fb_init(vd);
+
 	return (CN_INTERNAL);
 }
-

--Multipart=_Fri__17_Jan_2014_17_42_07_+0200_naE5YrvJnuCVT7_H--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140117174207.88bedb221f2ac942c607dbf1>