coreboot/payloads/libpayload/drivers/video/video.c
<<
>>
Prefs
   1/*
   2 * This file is part of the libpayload project.
   3 *
   4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
   5 *
   6 * Redistribution and use in source and binary forms, with or without
   7 * modification, are permitted provided that the following conditions
   8 * are met:
   9 * 1. Redistributions of source code must retain the above copyright
  10 *    notice, this list of conditions and the following disclaimer.
  11 * 2. Redistributions in binary form must reproduce the above copyright
  12 *    notice, this list of conditions and the following disclaimer in the
  13 *    documentation and/or other materials provided with the distribution.
  14 * 3. The name of the author may not be used to endorse or promote products
  15 *    derived from this software without specific prior written permission.
  16 *
  17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27 * SUCH DAMAGE.
  28 */
  29
  30#include <libpayload-config.h>
  31#include <libpayload.h>
  32#include <video_console.h>
  33
  34#ifdef CONFIG_GEODELX_VIDEO_CONSOLE
  35extern struct video_console geodelx_video_console;
  36#endif
  37
  38#ifdef CONFIG_COREBOOT_VIDEO_CONSOLE
  39extern struct video_console coreboot_video_console;
  40#endif
  41
  42#ifdef CONFIG_VGA_VIDEO_CONSOLE
  43extern struct video_console vga_video_console;
  44#endif
  45
  46static struct video_console *console_list[] =
  47{
  48#ifdef CONFIG_GEODELX_VIDEO_CONSOLE
  49        &geodelx_video_console,
  50#endif
  51#ifdef CONFIG_COREBOOT_VIDEO_CONSOLE
  52        &coreboot_video_console,
  53#endif
  54#ifdef CONFIG_VGA_VIDEO_CONSOLE
  55        &vga_video_console,
  56#endif
  57};
  58
  59static struct video_console *console;
  60
  61static int cursorx;
  62static int cursory;
  63static unsigned int cursor_enabled = 1;
  64
  65static void video_console_fixup_cursor(void)
  66{
  67        if (!cursor_enabled)
  68                return;
  69
  70        if (cursorx < 0)
  71                cursorx = 0;
  72
  73        if (cursory < 0)
  74                cursory = 0;
  75
  76        if (cursorx >= console->columns) {
  77                cursorx = 0;
  78                cursory++;
  79        }
  80
  81        while(cursory >= console->rows) {
  82                console->scroll_up();
  83                cursory--;
  84        }
  85
  86        if (console && console->set_cursor)
  87                console->set_cursor(cursorx, cursory);
  88}
  89
  90void video_console_cursor_enable(int state)
  91{
  92        if (console && console->enable_cursor)
  93                console->enable_cursor(state);
  94
  95        cursor_enabled = state;
  96
  97        if (cursor_enabled)
  98                video_console_fixup_cursor();
  99}
 100
 101void video_console_clear(void)
 102{
 103        if (console)
 104                console->clear();
 105
 106        cursorx = 0;
 107        cursory = 0;
 108
 109        if (console && console->set_cursor)
 110                console->set_cursor(cursorx, cursory);
 111}
 112
 113void video_console_putc(u8 row, u8 col, unsigned int ch)
 114{
 115        if (console)
 116                console->putc(row, col, ch);
 117}
 118
 119void video_console_putchar(unsigned int ch)
 120{
 121        /* replace black-on-black with light-gray-on-black.
 122         * do it here, instead of in libc/console.c
 123         */
 124        if ((ch & 0xFF00) == 0) {
 125                ch |= 0x0700;
 126        }
 127
 128        switch(ch & 0xFF) {
 129        case '\r':
 130                cursorx = 0;
 131                break;
 132
 133        case '\n':
 134                cursory++;
 135                break;
 136
 137        case '\b':
 138                cursorx--;
 139                if (cursorx < 0) {
 140                        cursory--;
 141                        cursorx = console->columns;
 142                }
 143                break;
 144
 145        case '\t':
 146                while(cursorx % 8 && cursorx < console->columns) {
 147                        if (console)
 148                                console->putc(cursory, cursorx, (ch & 0xFF00) | ' ');
 149
 150                        cursorx++;
 151                }
 152                break;
 153        default:
 154                if (console)
 155                        console->putc(cursory, cursorx++, ch);
 156                break;
 157        }
 158
 159        video_console_fixup_cursor();
 160}
 161
 162void video_console_get_cursor(unsigned int *x, unsigned int *y, unsigned int *en)
 163{
 164        *x=0;
 165        *y=0;
 166        *en=0;
 167
 168        if (console->get_cursor)
 169                console->get_cursor(x, y, en);
 170
 171        *x = cursorx;
 172        *y = cursory;
 173}
 174
 175void video_console_set_cursor(unsigned int x, unsigned int y)
 176{
 177        cursorx = x;
 178        cursory = y;
 179        video_console_fixup_cursor();
 180}
 181
 182static struct console_output_driver cons = {
 183        .putchar = video_console_putchar
 184};
 185
 186int video_console_init(void)
 187{
 188                int i;
 189
 190                for(i = 0; i < ARRAY_SIZE(console_list); i++) {
 191                        if (console_list[i]->init())
 192                                continue;
 193
 194                        console = console_list[i];
 195
 196                        if (console->get_cursor)
 197                                console->get_cursor((unsigned int*)&cursorx, (unsigned int*)&cursory, &cursor_enabled);
 198
 199                        if (cursorx) {
 200                                cursorx = 0;
 201                                cursory++;
 202                        }
 203
 204                        video_console_fixup_cursor();
 205                        console_add_output_driver(&cons);
 206                        return 0;
 207                }
 208
 209                return 0;
 210}
 211
 212
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.