aboutsummaryrefslogtreecommitdiff
path: root/src/pc80/vga/vga_io.c
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2009-05-29 03:04:16 +0000
committerLuc Verhaegen <libv@skynet.be>2009-05-29 03:04:16 +0000
commit5c5beb765dce9e5ded2ea1332d86d288ba347dce (patch)
tree2ac82209a29b6af718caf0813b83443f1363034a /src/pc80/vga/vga_io.c
parent195f5cd66674433cf06dbfe57e0b9bd98bb3549c (diff)
Implement native VGA Support.
This code brings a rather complete set of VGA IO routines for whoever wants it. These consist of the by now familiar read/write/mask sets. Due to the crazy nature of VGA, an ancient standard with bits all over the place, it makes no sense to define individual registers. You need a vga register spec at hand if you want to do anything anyway. These IO routines are always exposed. It also provides code to natively set up a 640x400 VGA textmode with an 8x16 font. The native VGA mode code is behind the OPTION_VGA option, as the font really adds to the size of the compiled/compressed rom. The font is the one also present in the linux kernel, but this file is unlicensed. Another copy of this is also present in coreboot in the deprecated console/btext code. The vga console code has been cleaned up, but it still has some TODO's left open, but that's for when i finally have found the remaining issue with the epia-m. Right now, it is important to get parts of my work out already and to make the remainder managable again. Signed-off-by: Luc Verhaegen <libv@skynet.be> Acked-by: Peter Stuge <peter@stuge.se> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4321 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src/pc80/vga/vga_io.c')
-rw-r--r--src/pc80/vga/vga_io.c275
1 files changed, 275 insertions, 0 deletions
diff --git a/src/pc80/vga/vga_io.c b/src/pc80/vga/vga_io.c
new file mode 100644
index 0000000000..c31287ab6d
--- /dev/null
+++ b/src/pc80/vga/vga_io.c
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2007-2009 Luc Verhaegen <libv@skynet.be>
+ *
+ * This program 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 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * All IO necessary to poke VGA registers.
+ */
+#include <pc80/vga_io.h>
+
+#include <arch/io.h>
+
+#define VGA_CR_INDEX 0x3D4
+#define VGA_CR_VALUE 0x3D5
+
+#define VGA_SR_INDEX 0x3C4
+#define VGA_SR_VALUE 0x3C5
+
+#define VGA_GR_INDEX 0x3CE
+#define VGA_GR_VALUE 0x3CF
+
+#define VGA_AR_INDEX 0x3C0
+#define VGA_AR_VALUE_READ 0x3C1
+#define VGA_AR_VALUE_WRITE VGA_AR_INDEX
+
+#define VGA_MISC_WRITE 0x3C2
+#define VGA_MISC_READ 0x3CC
+
+#define VGA_ENABLE 0x3C3
+#define VGA_STAT1 0x3DA
+
+#define VGA_DAC_MASK 0x3C6
+#define VGA_DAC_READ_ADDRESS 0x3C7
+#define VGA_DAC_WRITE_ADDRESS 0x3C8
+#define VGA_DAC_DATA 0x3C9
+
+/*
+ * VGA enable. Poke this to have the PCI IO enabled device accept VGA IO.
+ */
+unsigned char
+vga_enable_read(void)
+{
+ return inb(VGA_ENABLE);
+}
+
+void
+vga_enable_write(unsigned char value)
+{
+ outb(value, VGA_ENABLE);
+}
+
+void
+vga_enable_mask(unsigned char value, unsigned char mask)
+{
+ unsigned char tmp;
+
+ tmp = vga_enable_read();
+ tmp &= ~mask;
+ tmp |= (value & mask);
+ vga_enable_write(tmp);
+}
+
+/*
+ * Miscellaneous register.
+ */
+unsigned char
+vga_misc_read(void)
+{
+ return inb(VGA_MISC_READ);
+}
+
+void
+vga_misc_write(unsigned char value)
+{
+ outb(value, VGA_MISC_WRITE);
+}
+
+void
+vga_misc_mask(unsigned char value, unsigned char mask)
+{
+ unsigned char tmp;
+
+ tmp = vga_misc_read();
+ tmp &= ~mask;
+ tmp |= (value & mask);
+ vga_misc_write(tmp);
+}
+
+/*
+ * Sequencer registers.
+ */
+unsigned char
+vga_sr_read(unsigned char index)
+{
+ outb(index, VGA_SR_INDEX);
+ return (inb(VGA_SR_VALUE));
+}
+
+void
+vga_sr_write(unsigned char index, unsigned char value)
+{
+ outb(index, VGA_SR_INDEX);
+ outb(value, VGA_SR_VALUE);
+}
+
+void
+vga_sr_mask(unsigned char index, unsigned char value, unsigned char mask)
+{
+ unsigned char tmp;
+
+ tmp = vga_sr_read(index);
+ tmp &= ~mask;
+ tmp |= (value & mask);
+ vga_sr_write(index, tmp);
+}
+
+/*
+ * CRTC registers.
+ */
+unsigned char
+vga_cr_read(unsigned char index)
+{
+ outb(index, VGA_CR_INDEX);
+ return (inb(VGA_CR_VALUE));
+}
+
+void
+vga_cr_write(unsigned char index, unsigned char value)
+{
+ outb(index, VGA_CR_INDEX);
+ outb(value, VGA_CR_VALUE);
+}
+
+void
+vga_cr_mask(unsigned char index, unsigned char value, unsigned char mask)
+{
+ unsigned char tmp;
+
+ tmp = vga_cr_read(index);
+ tmp &= ~mask;
+ tmp |= (value & mask);
+ vga_cr_write(index, tmp);
+}
+
+/*
+ * Attribute registers.
+ */
+unsigned char
+vga_ar_read(unsigned char index)
+{
+ unsigned char ret;
+
+ (void) inb(VGA_STAT1);
+ outb(index, VGA_AR_INDEX);
+ ret = inb(VGA_AR_VALUE_READ);
+ (void) inb(VGA_STAT1);
+
+ return ret;
+}
+
+void
+vga_ar_write(unsigned char index, unsigned char value)
+{
+ (void) inb(VGA_STAT1);
+ outb(index, VGA_AR_INDEX);
+ outb(value, VGA_AR_VALUE_WRITE);
+ (void) inb(VGA_STAT1);
+}
+
+void
+vga_ar_mask(unsigned char index, unsigned char value, unsigned char mask)
+{
+ unsigned char tmp;
+
+ tmp = vga_ar_read(index);
+ tmp &= ~mask;
+ tmp |= (value & mask);
+ vga_ar_write(index, tmp);
+}
+
+/*
+ * Graphics registers.
+ */
+unsigned char
+vga_gr_read(unsigned char index)
+{
+ outb(index, VGA_GR_INDEX);
+ return (inb(VGA_GR_VALUE));
+}
+
+void
+vga_gr_write(unsigned char index, unsigned char value)
+{
+ outb(index, VGA_GR_INDEX);
+ outb(value, VGA_GR_VALUE);
+}
+
+void
+vga_gr_mask(unsigned char index, unsigned char value, unsigned char mask)
+{
+ unsigned char tmp;
+
+ tmp = vga_gr_read(index);
+ tmp &= ~mask;
+ tmp |= (value & mask);
+ vga_gr_write(index, tmp);
+}
+
+/*
+ * DAC functions.
+ */
+void
+vga_palette_enable(void)
+{
+ (void) inb(VGA_STAT1);
+ outb(0x00, VGA_AR_INDEX);
+ (void) inb(VGA_STAT1);
+}
+
+void
+vga_palette_disable(void)
+{
+ (void) inb(VGA_STAT1);
+ outb(0x20, VGA_AR_INDEX);
+ (void) inb(VGA_STAT1);
+}
+
+unsigned char
+vga_dac_mask_read(void)
+{
+ return inb(VGA_DAC_MASK);
+}
+
+void
+vga_dac_mask_write(unsigned char mask)
+{
+ outb(mask, VGA_DAC_MASK);
+}
+
+void
+vga_dac_read_address(unsigned char address)
+{
+ outb(address, VGA_DAC_READ_ADDRESS);
+}
+
+void
+vga_dac_write_address(unsigned char address)
+{
+ outb(address, VGA_DAC_WRITE_ADDRESS);
+}
+
+unsigned char
+vga_dac_data_read(void)
+{
+ return inb(VGA_DAC_DATA);
+}
+
+void
+vga_dac_data_write(unsigned char data)
+{
+ outb(data, VGA_DAC_DATA);
+}