2010-05-15 23:32:07 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define grub_video_render_target grub_video_fbrender_target
|
|
|
|
|
|
|
|
#include <grub/err.h>
|
|
|
|
#include <grub/types.h>
|
|
|
|
#include <grub/dl.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/video.h>
|
|
|
|
#include <grub/video_fb.h>
|
|
|
|
#include <grub/pci.h>
|
2010-05-17 00:25:37 +00:00
|
|
|
#include <grub/vga.h>
|
2010-05-15 23:32:07 +00:00
|
|
|
|
2011-04-11 21:01:51 +00:00
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
struct grub_video_mode_info mode_info;
|
2010-05-16 18:20:31 +00:00
|
|
|
grub_size_t page_size; /* The size of a page in bytes. */
|
2010-05-15 23:32:07 +00:00
|
|
|
|
|
|
|
grub_uint8_t *ptr;
|
|
|
|
int mapped;
|
|
|
|
grub_uint32_t base;
|
|
|
|
grub_pci_device_t dev;
|
|
|
|
} framebuffer;
|
|
|
|
|
2010-05-16 20:20:19 +00:00
|
|
|
#define CIRRUS_APERTURE_SIZE 0x1000000
|
2010-05-15 23:32:07 +00:00
|
|
|
|
|
|
|
#define CIRRUS_MAX_WIDTH 0x800
|
|
|
|
#define CIRRUS_MAX_HEIGHT 0x800
|
2010-05-17 00:25:37 +00:00
|
|
|
#define CIRRUS_MAX_PITCH (0x1ff * GRUB_VGA_CR_PITCH_DIVISOR)
|
2010-05-15 23:32:07 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CIRRUS_CR_EXTENDED_DISPLAY = 0x1b,
|
2010-05-16 18:20:31 +00:00
|
|
|
CIRRUS_CR_EXTENDED_OVERLAY = 0x1d,
|
2010-05-15 23:32:07 +00:00
|
|
|
CIRRUS_CR_MAX
|
|
|
|
};
|
|
|
|
|
2010-05-16 18:20:31 +00:00
|
|
|
#define CIRRUS_CR_EXTENDED_DISPLAY_PITCH_MASK 0x10
|
|
|
|
#define CIRRUS_CR_EXTENDED_DISPLAY_PITCH_SHIFT 4
|
|
|
|
#define CIRRUS_CR_EXTENDED_DISPLAY_START_MASK1 0x1
|
|
|
|
#define CIRRUS_CR_EXTENDED_DISPLAY_START_SHIFT1 16
|
|
|
|
#define CIRRUS_CR_EXTENDED_DISPLAY_START_MASK2 0xc
|
|
|
|
#define CIRRUS_CR_EXTENDED_DISPLAY_START_SHIFT2 15
|
|
|
|
|
|
|
|
#define CIRRUS_CR_EXTENDED_OVERLAY_DISPLAY_START_MASK 0x80
|
|
|
|
#define CIRRUS_CR_EXTENDED_OVERLAY_DISPLAY_START_SHIFT 12
|
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CIRRUS_SR_EXTENDED_MODE = 7,
|
|
|
|
CIRRUS_SR_MAX
|
|
|
|
};
|
2010-05-17 00:25:37 +00:00
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
#define CIRRUS_SR_EXTENDED_MODE_LFB_ENABLE 0xf0
|
|
|
|
#define CIRRUS_SR_EXTENDED_MODE_ENABLE_EXT 0x01
|
2010-05-16 19:18:40 +00:00
|
|
|
#define CIRRUS_SR_EXTENDED_MODE_8BPP 0x00
|
2010-05-15 23:32:07 +00:00
|
|
|
#define CIRRUS_SR_EXTENDED_MODE_16BPP 0x06
|
2010-05-16 19:18:40 +00:00
|
|
|
#define CIRRUS_SR_EXTENDED_MODE_24BPP 0x04
|
2010-05-15 23:32:07 +00:00
|
|
|
#define CIRRUS_SR_EXTENDED_MODE_32BPP 0x08
|
|
|
|
|
2010-05-16 18:44:44 +00:00
|
|
|
#define CIRRUS_HIDDEN_DAC_ENABLE_EXT 0x80
|
|
|
|
#define CIRRUS_HIDDEN_DAC_ENABLE_ALL 0x40
|
2010-05-16 19:18:40 +00:00
|
|
|
#define CIRRUS_HIDDEN_DAC_8BPP 0
|
2010-05-16 18:44:44 +00:00
|
|
|
#define CIRRUS_HIDDEN_DAC_15BPP (CIRRUS_HIDDEN_DAC_ENABLE_EXT \
|
|
|
|
| CIRRUS_HIDDEN_DAC_ENABLE_ALL | 0)
|
|
|
|
#define CIRRUS_HIDDEN_DAC_16BPP (CIRRUS_HIDDEN_DAC_ENABLE_EXT \
|
|
|
|
| CIRRUS_HIDDEN_DAC_ENABLE_ALL | 1)
|
|
|
|
#define CIRRUS_HIDDEN_DAC_888COLOR (CIRRUS_HIDDEN_DAC_ENABLE_EXT \
|
|
|
|
| CIRRUS_HIDDEN_DAC_ENABLE_ALL | 5)
|
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
static void
|
|
|
|
write_hidden_dac (grub_uint8_t data)
|
|
|
|
{
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_inb (GRUB_VGA_IO_PALLETTE_WRITE_INDEX);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
grub_outb (data, GRUB_VGA_IO_PIXEL_MASK);
|
2010-05-15 23:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_uint8_t
|
|
|
|
read_hidden_dac (void)
|
|
|
|
{
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_inb (GRUB_VGA_IO_PALLETTE_WRITE_INDEX);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
|
|
|
return grub_inb (GRUB_VGA_IO_PIXEL_MASK);
|
2010-05-15 23:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct saved_state
|
|
|
|
{
|
|
|
|
grub_uint8_t cr[CIRRUS_CR_MAX];
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_uint8_t gr[GRUB_VGA_GR_MAX];
|
2010-05-15 23:32:07 +00:00
|
|
|
grub_uint8_t sr[CIRRUS_SR_MAX];
|
|
|
|
grub_uint8_t hidden_dac;
|
|
|
|
/* We need to preserve VGA font and VGA text. */
|
|
|
|
grub_uint8_t vram[32 * 4 * 256];
|
2010-05-16 19:18:40 +00:00
|
|
|
grub_uint8_t r[256];
|
|
|
|
grub_uint8_t g[256];
|
|
|
|
grub_uint8_t b[256];
|
2010-05-15 23:32:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct saved_state initial_state;
|
|
|
|
static int state_saved = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
save_state (struct saved_state *st)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE (st->cr); i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
st->cr[i] = grub_vga_cr_read (i);
|
2010-05-15 23:32:07 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (st->sr); i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
st->sr[i] = grub_vga_sr_read (i);
|
2010-05-15 23:32:07 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (st->gr); i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
st->gr[i] = grub_vga_gr_read (i);
|
2010-05-16 19:18:40 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_palette_read (i, st->r + i, st->g + i, st->b + i);
|
2010-05-16 19:18:40 +00:00
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
st->hidden_dac = read_hidden_dac ();
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_CHAIN4, GRUB_VGA_SR_MEMORY_MODE);
|
2010-05-15 23:32:07 +00:00
|
|
|
grub_memcpy (st->vram, framebuffer.ptr, sizeof (st->vram));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
restore_state (struct saved_state *st)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_CHAIN4, GRUB_VGA_SR_MEMORY_MODE);
|
2010-05-15 23:32:07 +00:00
|
|
|
grub_memcpy (framebuffer.ptr, st->vram, sizeof (st->vram));
|
|
|
|
for (i = 0; i < ARRAY_SIZE (st->cr); i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_cr_write (st->cr[i], i);
|
2010-05-15 23:32:07 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (st->sr); i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_sr_write (st->sr[i], i);
|
2010-05-15 23:32:07 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (st->gr); i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_gr_write (st->gr[i], i);
|
2010-05-16 19:18:40 +00:00
|
|
|
for (i = 0; i < 256; i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_palette_write (i, st->r[i], st->g[i], st->b[i]);
|
2010-05-16 19:18:40 +00:00
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
write_hidden_dac (st->hidden_dac);
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_video_cirrus_video_init (void)
|
|
|
|
{
|
|
|
|
/* Reset frame buffer. */
|
|
|
|
grub_memset (&framebuffer, 0, sizeof(framebuffer));
|
|
|
|
|
|
|
|
return grub_video_fb_init ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_video_cirrus_video_fini (void)
|
|
|
|
{
|
|
|
|
if (framebuffer.mapped)
|
|
|
|
grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr,
|
|
|
|
CIRRUS_APERTURE_SIZE);
|
|
|
|
|
|
|
|
if (state_saved)
|
|
|
|
{
|
|
|
|
restore_state (&initial_state);
|
|
|
|
state_saved = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return grub_video_fb_fini ();
|
|
|
|
}
|
|
|
|
|
2010-05-16 18:20:31 +00:00
|
|
|
static grub_err_t
|
|
|
|
doublebuf_pageflipping_set_page (int page)
|
|
|
|
{
|
|
|
|
int start = framebuffer.page_size * page / 4;
|
|
|
|
grub_uint8_t cr_ext, cr_overlay;
|
|
|
|
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_cr_write (start & 0xff, GRUB_VGA_CR_START_ADDR_LOW_REGISTER);
|
|
|
|
grub_vga_cr_write ((start & 0xff00) >> 8,
|
|
|
|
GRUB_VGA_CR_START_ADDR_HIGH_REGISTER);
|
2010-05-16 18:20:31 +00:00
|
|
|
|
2010-05-17 00:25:37 +00:00
|
|
|
cr_ext = grub_vga_cr_read (CIRRUS_CR_EXTENDED_DISPLAY);
|
2010-05-16 18:20:31 +00:00
|
|
|
cr_ext &= ~(CIRRUS_CR_EXTENDED_DISPLAY_START_MASK1
|
|
|
|
| CIRRUS_CR_EXTENDED_DISPLAY_START_MASK2);
|
|
|
|
cr_ext |= ((start >> CIRRUS_CR_EXTENDED_DISPLAY_START_SHIFT1)
|
|
|
|
& CIRRUS_CR_EXTENDED_DISPLAY_START_MASK1);
|
|
|
|
cr_ext |= ((start >> CIRRUS_CR_EXTENDED_DISPLAY_START_SHIFT2)
|
|
|
|
& CIRRUS_CR_EXTENDED_DISPLAY_START_MASK2);
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_cr_write (cr_ext, CIRRUS_CR_EXTENDED_DISPLAY);
|
2010-05-16 18:20:31 +00:00
|
|
|
|
2010-05-17 00:25:37 +00:00
|
|
|
cr_overlay = grub_vga_cr_read (CIRRUS_CR_EXTENDED_OVERLAY);
|
2010-05-16 18:20:31 +00:00
|
|
|
cr_overlay &= ~(CIRRUS_CR_EXTENDED_OVERLAY_DISPLAY_START_MASK);
|
|
|
|
cr_overlay |= ((start >> CIRRUS_CR_EXTENDED_OVERLAY_DISPLAY_START_SHIFT)
|
|
|
|
& CIRRUS_CR_EXTENDED_OVERLAY_DISPLAY_START_MASK);
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_cr_write (cr_overlay, CIRRUS_CR_EXTENDED_OVERLAY);
|
2010-05-16 18:20:31 +00:00
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2010-05-16 19:18:40 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_video_cirrus_set_palette (unsigned int start, unsigned int count,
|
|
|
|
struct grub_video_palette_data *palette_data)
|
|
|
|
{
|
|
|
|
if (framebuffer.mode_info.mode_type == GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
if (start >= 0x100)
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
if (start + count >= 0x100)
|
|
|
|
count = 0x100 - start;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_palette_write (start + i, palette_data[i].r, palette_data[i].g,
|
|
|
|
palette_data[i].b);
|
2010-05-16 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Then set color to emulated palette. */
|
|
|
|
return grub_video_fb_set_palette (start, count, palette_data);
|
|
|
|
}
|
|
|
|
|
2013-01-13 01:10:41 +00:00
|
|
|
/* Helper for grub_video_cirrus_setup. */
|
|
|
|
static int
|
|
|
|
find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
|
|
|
|
{
|
|
|
|
int *found = data;
|
|
|
|
grub_pci_address_t addr;
|
|
|
|
grub_uint32_t class;
|
|
|
|
|
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
|
|
|
class = grub_pci_read (addr);
|
|
|
|
|
|
|
|
if (((class >> 16) & 0xffff) != 0x0300 || pciid != 0x00b81013)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*found = 1;
|
|
|
|
|
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
|
|
|
|
framebuffer.base = grub_pci_read (addr) & GRUB_PCI_ADDR_MEM_MASK;
|
|
|
|
framebuffer.dev = dev;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
static grub_err_t
|
|
|
|
grub_video_cirrus_setup (unsigned int width, unsigned int height,
|
2011-03-23 10:54:58 +00:00
|
|
|
grub_video_mode_type_t mode_type,
|
|
|
|
grub_video_mode_type_t mode_mask)
|
2010-05-15 23:32:07 +00:00
|
|
|
{
|
|
|
|
int depth;
|
|
|
|
grub_err_t err;
|
|
|
|
int found = 0;
|
|
|
|
int pitch, bytes_per_pixel;
|
|
|
|
|
|
|
|
/* Decode depth from mode_type. If it is zero, then autodetect. */
|
|
|
|
depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
|
|
|
|
>> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;
|
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
{
|
|
|
|
width = 800;
|
|
|
|
height = 600;
|
|
|
|
}
|
|
|
|
|
2010-05-17 00:25:37 +00:00
|
|
|
if (width & (GRUB_VGA_CR_WIDTH_DIVISOR - 1))
|
2010-05-15 23:32:07 +00:00
|
|
|
return grub_error (GRUB_ERR_IO,
|
|
|
|
"screen width must be a multiple of %d",
|
2010-05-17 00:25:37 +00:00
|
|
|
GRUB_VGA_CR_WIDTH_DIVISOR);
|
2010-05-15 23:32:07 +00:00
|
|
|
|
|
|
|
if (width > CIRRUS_MAX_WIDTH)
|
|
|
|
return grub_error (GRUB_ERR_IO,
|
|
|
|
"screen width must be at most %d", CIRRUS_MAX_WIDTH);
|
|
|
|
|
|
|
|
if (height > CIRRUS_MAX_HEIGHT)
|
|
|
|
return grub_error (GRUB_ERR_IO,
|
|
|
|
"screen height must be at most %d", CIRRUS_MAX_HEIGHT);
|
|
|
|
|
2010-05-16 19:18:40 +00:00
|
|
|
if (depth == 0
|
|
|
|
&& !grub_video_check_mode_flag (mode_type, mode_mask,
|
|
|
|
GRUB_VIDEO_MODE_TYPE_INDEX_COLOR, 0))
|
2010-05-15 23:32:07 +00:00
|
|
|
depth = 24;
|
2013-05-02 20:30:20 +00:00
|
|
|
else if (depth == 0)
|
2010-05-16 19:18:40 +00:00
|
|
|
depth = 8;
|
|
|
|
|
|
|
|
if (depth != 32 && depth != 24 && depth != 16 && depth != 15 && depth != 8)
|
|
|
|
return grub_error (GRUB_ERR_IO, "only 32, 24, 16, 15 and 8-bit bpp are"
|
|
|
|
" supported by cirrus video");
|
2010-05-15 23:32:07 +00:00
|
|
|
|
2013-05-02 20:30:20 +00:00
|
|
|
bytes_per_pixel = (depth + GRUB_CHAR_BIT - 1) / GRUB_CHAR_BIT;
|
2010-05-15 23:32:07 +00:00
|
|
|
pitch = width * bytes_per_pixel;
|
|
|
|
|
|
|
|
if (pitch > CIRRUS_MAX_PITCH)
|
|
|
|
return grub_error (GRUB_ERR_IO,
|
|
|
|
"screen width must be at most %d at bitdepth %d",
|
|
|
|
CIRRUS_MAX_PITCH / bytes_per_pixel, depth);
|
|
|
|
|
2010-05-16 18:20:31 +00:00
|
|
|
framebuffer.page_size = pitch * height;
|
|
|
|
|
|
|
|
if (framebuffer.page_size > CIRRUS_APERTURE_SIZE)
|
|
|
|
return grub_error (GRUB_ERR_IO, "Not enough video memory for this mode");
|
|
|
|
|
2013-01-13 01:10:41 +00:00
|
|
|
grub_pci_iterate (find_card, &found);
|
2010-05-15 23:32:07 +00:00
|
|
|
if (!found)
|
|
|
|
return grub_error (GRUB_ERR_IO, "Couldn't find graphics card");
|
|
|
|
|
|
|
|
if (found && framebuffer.base == 0)
|
|
|
|
{
|
|
|
|
/* FIXME: change framebuffer base */
|
2010-05-16 18:20:31 +00:00
|
|
|
return grub_error (GRUB_ERR_IO, "PCI BAR not set");
|
2010-05-15 23:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We can safely discard volatile attribute. */
|
|
|
|
framebuffer.ptr = (void *) grub_pci_device_map_range (framebuffer.dev,
|
|
|
|
framebuffer.base,
|
|
|
|
CIRRUS_APERTURE_SIZE);
|
|
|
|
framebuffer.mapped = 1;
|
|
|
|
|
|
|
|
if (!state_saved)
|
|
|
|
{
|
|
|
|
save_state (&initial_state);
|
|
|
|
state_saved = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2010-08-11 02:18:07 +00:00
|
|
|
struct grub_video_hw_config config = {
|
|
|
|
.pitch = pitch / GRUB_VGA_CR_PITCH_DIVISOR,
|
|
|
|
.line_compare = 0x3ff,
|
|
|
|
.vdisplay_end = height - 1,
|
|
|
|
.horizontal_end = width / GRUB_VGA_CR_WIDTH_DIVISOR
|
|
|
|
};
|
2010-05-16 18:44:44 +00:00
|
|
|
grub_uint8_t sr_ext = 0, hidden_dac = 0;
|
2010-05-15 23:32:07 +00:00
|
|
|
|
2010-08-11 02:18:07 +00:00
|
|
|
grub_vga_set_geometry (&config, grub_vga_cr_write);
|
|
|
|
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_gr_write (GRUB_VGA_GR_MODE_256_COLOR | GRUB_VGA_GR_MODE_READ_MODE1,
|
|
|
|
GRUB_VGA_GR_MODE);
|
|
|
|
grub_vga_gr_write (GRUB_VGA_GR_GR6_GRAPHICS_MODE, GRUB_VGA_GR_GR6);
|
2010-05-15 23:32:07 +00:00
|
|
|
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_NORMAL, GRUB_VGA_SR_MEMORY_MODE);
|
2010-05-15 23:32:07 +00:00
|
|
|
|
2010-08-11 02:18:07 +00:00
|
|
|
grub_vga_cr_write ((config.pitch >> CIRRUS_CR_EXTENDED_DISPLAY_PITCH_SHIFT)
|
2010-05-15 23:32:07 +00:00
|
|
|
& CIRRUS_CR_EXTENDED_DISPLAY_PITCH_MASK,
|
|
|
|
CIRRUS_CR_EXTENDED_DISPLAY);
|
|
|
|
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_cr_write (GRUB_VGA_CR_MODE_TIMING_ENABLE
|
|
|
|
| GRUB_VGA_CR_MODE_BYTE_MODE
|
|
|
|
| GRUB_VGA_CR_MODE_NO_HERCULES | GRUB_VGA_CR_MODE_NO_CGA,
|
|
|
|
GRUB_VGA_CR_MODE);
|
2010-05-15 23:32:07 +00:00
|
|
|
|
2010-05-16 18:20:31 +00:00
|
|
|
doublebuf_pageflipping_set_page (0);
|
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
sr_ext = CIRRUS_SR_EXTENDED_MODE_LFB_ENABLE
|
|
|
|
| CIRRUS_SR_EXTENDED_MODE_ENABLE_EXT;
|
|
|
|
switch (depth)
|
|
|
|
{
|
2010-05-16 18:44:44 +00:00
|
|
|
/* FIXME: support 8-bit grayscale and 8-bit RGB. */
|
2010-05-15 23:32:07 +00:00
|
|
|
case 32:
|
2010-05-16 18:44:44 +00:00
|
|
|
hidden_dac = CIRRUS_HIDDEN_DAC_888COLOR;
|
2010-05-15 23:32:07 +00:00
|
|
|
sr_ext |= CIRRUS_SR_EXTENDED_MODE_32BPP;
|
|
|
|
break;
|
|
|
|
case 24:
|
2010-05-16 18:44:44 +00:00
|
|
|
hidden_dac = CIRRUS_HIDDEN_DAC_888COLOR;
|
2010-05-15 23:32:07 +00:00
|
|
|
sr_ext |= CIRRUS_SR_EXTENDED_MODE_24BPP;
|
|
|
|
break;
|
|
|
|
case 16:
|
2010-05-16 18:44:44 +00:00
|
|
|
hidden_dac = CIRRUS_HIDDEN_DAC_16BPP;
|
|
|
|
sr_ext |= CIRRUS_SR_EXTENDED_MODE_16BPP;
|
|
|
|
break;
|
2010-05-15 23:32:07 +00:00
|
|
|
case 15:
|
2010-05-16 18:44:44 +00:00
|
|
|
hidden_dac = CIRRUS_HIDDEN_DAC_15BPP;
|
2010-05-15 23:32:07 +00:00
|
|
|
sr_ext |= CIRRUS_SR_EXTENDED_MODE_16BPP;
|
|
|
|
break;
|
2010-05-16 19:18:40 +00:00
|
|
|
case 8:
|
|
|
|
hidden_dac = CIRRUS_HIDDEN_DAC_8BPP;
|
|
|
|
sr_ext |= CIRRUS_SR_EXTENDED_MODE_8BPP;
|
|
|
|
break;
|
2010-05-15 23:32:07 +00:00
|
|
|
}
|
2010-05-17 00:25:37 +00:00
|
|
|
grub_vga_sr_write (sr_ext, CIRRUS_SR_EXTENDED_MODE);
|
2010-05-16 18:44:44 +00:00
|
|
|
write_hidden_dac (hidden_dac);
|
2010-05-15 23:32:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill mode info details. */
|
|
|
|
framebuffer.mode_info.width = width;
|
|
|
|
framebuffer.mode_info.height = height;
|
|
|
|
framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
|
|
|
|
framebuffer.mode_info.bpp = depth;
|
|
|
|
framebuffer.mode_info.bytes_per_pixel = bytes_per_pixel;
|
|
|
|
framebuffer.mode_info.pitch = pitch;
|
|
|
|
framebuffer.mode_info.number_of_colors = 256;
|
|
|
|
framebuffer.mode_info.reserved_mask_size = 0;
|
|
|
|
framebuffer.mode_info.reserved_field_pos = 0;
|
|
|
|
|
|
|
|
switch (depth)
|
|
|
|
{
|
2010-05-16 19:18:40 +00:00
|
|
|
case 8:
|
|
|
|
framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
|
2013-05-02 20:30:20 +00:00
|
|
|
framebuffer.mode_info.number_of_colors = 16;
|
2010-05-16 19:18:40 +00:00
|
|
|
break;
|
2010-05-15 23:32:07 +00:00
|
|
|
case 16:
|
|
|
|
framebuffer.mode_info.red_mask_size = 5;
|
|
|
|
framebuffer.mode_info.red_field_pos = 11;
|
|
|
|
framebuffer.mode_info.green_mask_size = 6;
|
|
|
|
framebuffer.mode_info.green_field_pos = 5;
|
|
|
|
framebuffer.mode_info.blue_mask_size = 5;
|
|
|
|
framebuffer.mode_info.blue_field_pos = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
framebuffer.mode_info.red_mask_size = 5;
|
|
|
|
framebuffer.mode_info.red_field_pos = 10;
|
|
|
|
framebuffer.mode_info.green_mask_size = 5;
|
|
|
|
framebuffer.mode_info.green_field_pos = 5;
|
|
|
|
framebuffer.mode_info.blue_mask_size = 5;
|
|
|
|
framebuffer.mode_info.blue_field_pos = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 32:
|
|
|
|
framebuffer.mode_info.reserved_mask_size = 8;
|
|
|
|
framebuffer.mode_info.reserved_field_pos = 24;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
framebuffer.mode_info.red_mask_size = 8;
|
|
|
|
framebuffer.mode_info.red_field_pos = 16;
|
|
|
|
framebuffer.mode_info.green_mask_size = 8;
|
|
|
|
framebuffer.mode_info.green_field_pos = 8;
|
|
|
|
framebuffer.mode_info.blue_mask_size = 8;
|
|
|
|
framebuffer.mode_info.blue_field_pos = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info);
|
|
|
|
|
2010-05-16 18:20:31 +00:00
|
|
|
if (CIRRUS_APERTURE_SIZE >= 2 * framebuffer.page_size)
|
|
|
|
err = grub_video_fb_setup (mode_type, mode_mask,
|
|
|
|
&framebuffer.mode_info,
|
|
|
|
framebuffer.ptr,
|
|
|
|
doublebuf_pageflipping_set_page,
|
|
|
|
framebuffer.ptr + framebuffer.page_size);
|
|
|
|
else
|
|
|
|
err = grub_video_fb_setup (mode_type, mode_mask,
|
|
|
|
&framebuffer.mode_info,
|
|
|
|
framebuffer.ptr, 0, 0);
|
2010-05-15 23:32:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Copy default palette to initialize emulated palette. */
|
2010-05-16 19:18:40 +00:00
|
|
|
err = grub_video_cirrus_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
|
|
|
|
grub_video_fbstd_colors);
|
2010-05-15 23:32:07 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct grub_video_adapter grub_video_cirrus_adapter =
|
|
|
|
{
|
|
|
|
.name = "Cirrus CLGD 5446 PCI Video Driver",
|
|
|
|
.id = GRUB_VIDEO_DRIVER_CIRRUS,
|
|
|
|
|
2010-06-20 12:15:20 +00:00
|
|
|
.prio = GRUB_VIDEO_ADAPTER_PRIO_NATIVE,
|
|
|
|
|
2010-05-15 23:32:07 +00:00
|
|
|
.init = grub_video_cirrus_video_init,
|
|
|
|
.fini = grub_video_cirrus_video_fini,
|
|
|
|
.setup = grub_video_cirrus_setup,
|
|
|
|
.get_info = grub_video_fb_get_info,
|
2010-05-16 18:20:31 +00:00
|
|
|
.get_info_and_fini = grub_video_fb_get_info_and_fini,
|
2010-05-15 23:32:07 +00:00
|
|
|
.set_palette = grub_video_cirrus_set_palette,
|
|
|
|
.get_palette = grub_video_fb_get_palette,
|
|
|
|
.set_viewport = grub_video_fb_set_viewport,
|
|
|
|
.get_viewport = grub_video_fb_get_viewport,
|
2013-11-08 11:42:38 +00:00
|
|
|
.set_region = grub_video_fb_set_region,
|
|
|
|
.get_region = grub_video_fb_get_region,
|
|
|
|
.set_area_status = grub_video_fb_set_area_status,
|
|
|
|
.get_area_status = grub_video_fb_get_area_status,
|
2010-05-15 23:32:07 +00:00
|
|
|
.map_color = grub_video_fb_map_color,
|
|
|
|
.map_rgb = grub_video_fb_map_rgb,
|
|
|
|
.map_rgba = grub_video_fb_map_rgba,
|
|
|
|
.unmap_color = grub_video_fb_unmap_color,
|
|
|
|
.fill_rect = grub_video_fb_fill_rect,
|
|
|
|
.blit_bitmap = grub_video_fb_blit_bitmap,
|
|
|
|
.blit_render_target = grub_video_fb_blit_render_target,
|
|
|
|
.scroll = grub_video_fb_scroll,
|
2010-05-16 18:20:31 +00:00
|
|
|
.swap_buffers = grub_video_fb_swap_buffers,
|
2010-05-15 23:32:07 +00:00
|
|
|
.create_render_target = grub_video_fb_create_render_target,
|
|
|
|
.delete_render_target = grub_video_fb_delete_render_target,
|
2010-05-16 18:20:31 +00:00
|
|
|
.set_active_render_target = grub_video_fb_set_active_render_target,
|
2010-05-15 23:32:07 +00:00
|
|
|
.get_active_render_target = grub_video_fb_get_active_render_target,
|
|
|
|
|
|
|
|
.next = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
GRUB_MOD_INIT(video_cirrus)
|
|
|
|
{
|
|
|
|
grub_video_register (&grub_video_cirrus_adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
GRUB_MOD_FINI(video_cirrus)
|
|
|
|
{
|
|
|
|
grub_video_unregister (&grub_video_cirrus_adapter);
|
|
|
|
}
|