From owner-svn-src-user@FreeBSD.ORG Thu Oct 17 12:58:41 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 591168E1; Thu, 17 Oct 2013 12:58:41 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 464792D91; Thu, 17 Oct 2013 12:58:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9HCwfZ8081962; Thu, 17 Oct 2013 12:58:41 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9HCwf9D081961; Thu, 17 Oct 2013 12:58:41 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201310171258.r9HCwf9D081961@svn.freebsd.org> From: Nathan Whitehorn Date: Thu, 17 Oct 2013 12:58:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256684 - user/ed/newcons/sys/dev/vt/hw/ofwfb X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Oct 2013 12:58:41 -0000 Author: nwhitehorn Date: Thu Oct 17 12:58:40 2013 New Revision: 256684 URL: http://svnweb.freebsd.org/changeset/base/256684 Log: Use vt_generate_vga_palette() instead of a hard-coded mapping. Modified: user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Modified: user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c ============================================================================== --- user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Thu Oct 17 12:43:29 2013 (r256683) +++ user/ed/newcons/sys/dev/vt/hw/ofwfb/ofwfb.c Thu Oct 17 12:58:40 2013 (r256684) @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD: user/ed/newcons/sys/ #include #include +#include #include #include @@ -52,7 +53,9 @@ struct ofwfb_softc { int sc_depth; int sc_stride; - bus_space_tag_t sc_memt; + bus_space_tag_t sc_memt; + + uint32_t sc_colormap[16]; }; static vd_init_t ofwfb_init; @@ -71,25 +74,6 @@ VT_CONSDEV_DECLARE(vt_ofwfb_driver, PIXE &ofwfb_conssoftc); /* XXX: hardcoded max size */ -static const uint32_t colormap[] = { - 0x00000000, /* Black */ - 0x00ff0000, /* Red */ - 0x0000ff00, /* Green */ - 0x00c0c000, /* Brown */ - 0x000000ff, /* Blue */ - 0x00c000c0, /* Magenta */ - 0x0000c0c0, /* Cyan */ - 0x00c0c0c0, /* Light grey */ - 0x00808080, /* Dark grey */ - 0x00ff8080, /* Light red */ - 0x0080ff80, /* Light green */ - 0x00ffff80, /* Yellow */ - 0x008080ff, /* Light blue */ - 0x00ff80ff, /* Light magenta */ - 0x0080ffff, /* Light cyan */ - 0x00ffffff, /* White */ -}; - static void ofwfb_blank(struct vt_device *vd, term_color_t color) { @@ -103,7 +87,7 @@ ofwfb_blank(struct vt_device *vd, term_c *(uint8_t *)(sc->sc_addr + ofs) = color; break; case 32: - c = colormap[color]; + 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; @@ -124,8 +108,8 @@ ofwfb_bitbltchr(struct vt_device *vd, co int c; uint8_t b = 0; - fgc = colormap[fg]; - bgc = colormap[bg]; + fgc = sc->sc_colormap[fg]; + bgc = sc->sc_colormap[bg]; line = (sc->sc_stride * top) + left * sc->sc_depth/8; for (; height > 0; height--) { @@ -160,23 +144,53 @@ ofwfb_initialize(struct vt_device *vd) ihandle_t ih; int i; cell_t retval; + uint32_t oldpix; /* Open display device, thereby initializing it */ memset(name, 0, sizeof(name)); OF_package_to_path(sc->sc_node, name, sizeof(name)); ih = OF_open(name); - if (sc->sc_depth == 8) { - /* - * Install the color map - */ + /* + * Set up the color map + */ + + switch (sc->sc_depth) { + case 8: + vt_generate_vga_palette(sc->sc_colormap, COLOR_FORMAT_RGB, 255, + 16, 255, 8, 255, 0); + for (i = 0; i < 16; i++) { OF_call_method("color!", ih, 4, 1, - (cell_t)((colormap[i] >> 16) & 0xff), - (cell_t)((colormap[i] >> 8) & 0xff), - (cell_t)((colormap[i] >> 0) & 0xff), + (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)i, &retval); } + break; + + case 32: + /* + * We bypass the usual bus_space_() accessors here, mostly + * for performance reasons. In particular, we don't want + * any barrier operations that may be performed and handle + * 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, + COLOR_FORMAT_RGB, 255, 16, 255, 8, 255, 0); + else + vt_generate_vga_palette(sc->sc_colormap, + COLOR_FORMAT_RGB, 255, 0, 255, 8, 255, 16); + bus_space_write_4(sc->sc_memt, sc->sc_addr, 0, oldpix); + break; + + default: + panic("Unknown color space depth %d", sc->sc_depth); + break; } /* Clear the screen. */ @@ -258,11 +272,11 @@ ofwfb_init(struct vt_device *vd) * Grab the physical address of the framebuffer, and then map it * into our memory space. If the MMU is not yet up, it will be * remapped for us when relocation turns on. - * - * XXX We assume #address-cells is 1 at this point. */ if (OF_getproplen(node, "address") == sizeof(fb_phys)) { + /* XXX We assume #address-cells is 1 at this point. */ OF_getprop(node, "address", &fb_phys, sizeof(fb_phys)); + #if defined(__powerpc__) sc->sc_memt = &bs_be_tag; bus_space_map(sc->sc_memt, fb_phys, height * sc->sc_stride,