Author: mcayland Date: Sat Jul 27 12:14:50 2013 New Revision: 1184 URL: http://tracker.coreboot.org/trac/openbios/changeset/1184
Log: video_common.c: move colour palette code into individual devices
Instead if having a large #ifdef .. #endif section in video_set_color(), move the device-specific hardware setters into each display device package.
To do this, we keep track of the display ihandle in the video structure and use it to invoke the low-level hardware setter routine (and optional palette refresh) if required.
Also since the display-ih isn't called until is-install, defer the colour palette initialisation from init_video() to is-install.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
Modified: trunk/openbios-devel/arch/sparc32/console.c trunk/openbios-devel/drivers/sbus.c trunk/openbios-devel/drivers/vga_vbe.c trunk/openbios-devel/forth/device/display.fs trunk/openbios-devel/include/drivers/drivers.h trunk/openbios-devel/include/libopenbios/video.h trunk/openbios-devel/libopenbios/video_common.c trunk/openbios-devel/packages/molvideo.c
Modified: trunk/openbios-devel/arch/sparc32/console.c ============================================================================== --- trunk/openbios-devel/arch/sparc32/console.c Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/arch/sparc32/console.c Sat Jul 27 12:14:50 2013 (r1184) @@ -11,6 +11,7 @@ #include "openbios.h" #include "libopenbios/console.h" #include "libopenbios/ofmem.h" +#include "libopenbios/video.h"
void cls(void);
@@ -41,6 +42,22 @@ dac = (uint32_t *)ofmem_map_io(base + DAC_BASE, DAC_SIZE); }
+/* ( r g b index -- ) */ +void tcx_hw_set_color(void) +{ + int index = POP(); + int b = POP(); + int g = POP(); + int r = POP(); + + if( VIDEO_DICT_VALUE(video.depth) == 8 ) { + dac[0] = index << 24; + dac[1] = r << 24; // Red + dac[1] = g << 24; // Green + dac[1] = b << 24; // Blue + } +} + #endif
/* ******************************************************************
Modified: trunk/openbios-devel/drivers/sbus.c ============================================================================== --- trunk/openbios-devel/drivers/sbus.c Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/drivers/sbus.c Sat Jul 27 12:14:50 2013 (r1184) @@ -329,6 +329,7 @@ fword("property"); }
+ bind_func("hw-set-color", tcx_hw_set_color); feval("['] qemu-tcx-driver-init is-install");
chosen = find_dev("/chosen");
Modified: trunk/openbios-devel/drivers/vga_vbe.c ============================================================================== --- trunk/openbios-devel/drivers/vga_vbe.c Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/drivers/vga_vbe.c Sat Jul 27 12:14:50 2013 (r1184) @@ -103,6 +103,22 @@ vga_build_rgb_palette(); }
+/* Low-level Forth accessor to update VGA color registers */ + +/* ( r g b index -- ) */ +static +void vga_hw_set_color(void) +{ + int index = POP(); + int b = POP(); + int g = POP(); + int r = POP(); + + vga_set_color(index, (r & 0xff), + (g & 0xff), + (b & 0xff)); +} + void vga_vbe_init(const char *path, unsigned long fb, uint32_t fb_size, unsigned long rom, uint32_t rom_size) { @@ -128,6 +144,8 @@ ph = get_cur_dev(); #endif
+ bind_func("hw-set-color", vga_hw_set_color); + set_int_property(ph, "width", VIDEO_DICT_VALUE(video.w)); set_int_property(ph, "height", VIDEO_DICT_VALUE(video.h)); set_int_property(ph, "depth", VIDEO_DICT_VALUE(video.depth));
Modified: trunk/openbios-devel/forth/device/display.fs ============================================================================== --- trunk/openbios-devel/forth/device/display.fs Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/forth/device/display.fs Sat Jul 27 12:14:50 2013 (r1184) @@ -48,6 +48,7 @@ 2 value font-spacing 0 value depth-bits 0 value line-bytes +0 value display-ih
\ internal values read from QEMU firmware interface 0 value qemu-video-addr @@ -353,6 +354,8 @@ 0 to inverse? 0 to inverse-screen?
+ my-self to display-ih + \ set defer functions to 8bit versions
['] fb8-draw-character to draw-character @@ -375,6 +378,28 @@ then to foreground-color to background-color
+ \ setup palette + 10101 ['] color-palette cell+ ff 0 do + dup 2 pick i * swap ! cell+ + loop 2drop + + \ special background color + ffffcc ['] color-palette cell+ fe cells + ! + + \ load palette onto the hardware + ['] color-palette cell+ ff 0 do + dup @ ff0000 and d# 16 rshift + 1 pick @ ff00 and d# 8 rshift + 2 pick @ ff and + i + s" hw-set-color" $find if + execute + else + 2drop + then + cell+ + loop drop + \ ... but let's override with some better defaults fe to background-color 0 to foreground-color
Modified: trunk/openbios-devel/include/drivers/drivers.h ============================================================================== --- trunk/openbios-devel/include/drivers/drivers.h Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/include/drivers/drivers.h Sat Jul 27 12:14:50 2013 (r1184) @@ -47,6 +47,7 @@
/* arch/sparc32/console.c */ void tcx_init(uint64_t base); +void tcx_hw_set_color(void); void kbd_init(uint64_t base); #endif #ifdef CONFIG_DRIVER_IDE
Modified: trunk/openbios-devel/include/libopenbios/video.h ============================================================================== --- trunk/openbios-devel/include/libopenbios/video.h Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/include/libopenbios/video.h Sat Jul 27 12:14:50 2013 (r1184) @@ -30,6 +30,7 @@ extern struct video_info { int has_video;
+ volatile ihandle_t *ih; volatile phys_addr_t mphys; volatile ucell *mvirt; volatile ucell *rb, *w, *h, *depth;
Modified: trunk/openbios-devel/libopenbios/video_common.c ============================================================================== --- trunk/openbios-devel/libopenbios/video_common.c Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/libopenbios/video_common.c Sat Jul 27 12:14:50 2013 (r1184) @@ -46,27 +46,30 @@ void video_set_color( int ind, unsigned long color ) { + xt_t hw_xt = 0; + if( !video.has_video || ind < 0 || ind > 255 ) return; video.pal[ind] = color;
-#ifdef CONFIG_MOL - if( VIDEO_DICT_VALUE(video.depth) == 8 ) - OSI_SetColor( ind, color ); -#elif defined(CONFIG_SPARC32) -#if defined(CONFIG_DEBUG_CONSOLE_VIDEO) - if( VIDEO_DICT_VALUE(video.depth) == 8 ) { - dac[0] = ind << 24; - dac[1] = ((color >> 16) & 0xff) << 24; // Red - dac[1] = ((color >> 8) & 0xff) << 24; // Green - dac[1] = (color & 0xff) << 24; // Blue - } -#endif -#else - vga_set_color(ind, ((color >> 16) & 0xff), - ((color >> 8) & 0xff), - (color & 0xff)); -#endif + /* Call the low-level hardware setter in the + display package */ + hw_xt = find_ih_method("hw-set-color", VIDEO_DICT_VALUE(video.ih)); + if (hw_xt) { + PUSH((color >> 16) & 0xff); // Red + PUSH((color >> 8) & 0xff); // Green + PUSH(color & 0xff); // Blue + PUSH(ind); + PUSH(hw_xt); + fword("execute"); + } + + /* Call the low-level palette update if required */ + hw_xt = find_ih_method("hw-refresh-palette", VIDEO_DICT_VALUE(video.ih)); + if (hw_xt) { + PUSH(hw_xt); + fword("execute"); + } }
/* ( fbaddr maskaddr width height fgcolor bgcolor -- ) */ @@ -219,6 +222,9 @@
video.mphys = phys;
+ feval("['] display-ih cell+"); + video.ih = cell2pointer(POP()); + feval("['] qemu-video-addr cell+"); video.mvirt = cell2pointer(POP()); feval("['] qemu-video-width cell+"); @@ -277,7 +283,6 @@ void init_video(void) { - int i; #if defined(CONFIG_OFMEM) && defined(CONFIG_DRIVER_PCI) int size; #endif @@ -306,9 +311,4 @@ ofmem_claim_virt( VIDEO_DICT_VALUE(video.mvirt), size, 0 ); ofmem_map( video.mphys, VIDEO_DICT_VALUE(video.mvirt), size, ofmem_arch_io_translation_mode(video.mphys) ); #endif - - for( i=0; i<256; i++ ) - video_set_color( i, i * 0x010101 ); - - video_set_color( 254, 0xffffcc ); }
Modified: trunk/openbios-devel/packages/molvideo.c ============================================================================== --- trunk/openbios-devel/packages/molvideo.c Sat Jul 27 12:14:47 2013 (r1183) +++ trunk/openbios-devel/packages/molvideo.c Sat Jul 27 12:14:50 2013 (r1184) @@ -31,15 +31,24 @@
DECLARE_NODE( video, 0, 0, "Tdisplay" );
+#ifdef CONFIG_MOL static void molvideo_refresh_palette( void ) { -#ifdef CONFIG_MOL + if( VIDEO_DICT_VALUE(video.depth) == 8 ) OSI_RefreshPalette(); -#endif }
+static void +molvideo_hw_set_color( void ) +{ + + if( VIDEO_DICT_VALUE(video.depth) == 8 ) + OSI_SetColor( ind, color ); +} +#endif + /* ( -- width height ) (?) */ static void molvideo_dimensions( void ) @@ -61,7 +70,6 @@ unsigned long col = (p[0] << 16) | (p[1] << 8) | p[2]; video_set_color( i + start, col ); } - molvideo_refresh_palette(); }
/* ( r g b index -- ) */ @@ -75,7 +83,6 @@ unsigned long col = ((r << 16) & 0xff0000) | ((g << 8) & 0x00ff00) | (b & 0xff); /* printk("color!: %08lx %08lx %08lx %08lx\n", r, g, b, index ); */ video_set_color( index, col ); - molvideo_refresh_palette(); }
/* ( color_ind x y width height -- ) (?) */ @@ -143,6 +150,10 @@
NODE_METHODS( video ) = { +#ifdef CONFIG_MOL + {"hw-set-color", molvideo_hw_set_color }, + {"hw-refresh-palette", molvideo_refresh_palette}, +#endif {"dimensions", molvideo_dimensions }, {"set-colors", molvideo_set_colors }, {"fill-rectangle", molvideo_fill_rect },