| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <libpayload.h> |
| 30 |
#include <pci.h> |
| 31 |
#include <video_console.h> |
| 32 |
#include <arch/msr.h> |
| 33 |
#include "font.h" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
static const struct mode { |
| 38 |
unsigned int pll; |
| 39 |
unsigned int hactive, hblankstart, hsyncstart; |
| 40 |
unsigned int hsyncend, hblankend, htotal; |
| 41 |
unsigned int vactive, vblankstart, vsyncstart; |
| 42 |
unsigned int vsyncend, vblankend, vtotal; |
| 43 |
unsigned int synccfg; |
| 44 |
} vga_mode = { |
| 45 |
.pll = 0x215D, |
| 46 |
.hactive = 640, |
| 47 |
.vactive = 400, |
| 48 |
.hblankstart = 640, |
| 49 |
.hsyncstart = 640 + 40, |
| 50 |
.hsyncend = 640 + 40 + 96, |
| 51 |
.hblankend = 640 + 40 + 96 + 24, |
| 52 |
.htotal = 640 + 40 + 96 + 24, |
| 53 |
.vblankstart = 400, |
| 54 |
.vsyncstart = 400 + 39, |
| 55 |
.vsyncend = 400 + 39 + 2, |
| 56 |
.vblankend = 400 + 39 + 2 + 9, |
| 57 |
.vtotal = 400 + 39 + 2 + 9, |
| 58 |
.synccfg = 0x300, |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
static const unsigned int vga_colors[] = { |
| 64 |
(0x00 << 16) | (0x00 << 8) | 0x00, |
| 65 |
(0xAA << 16) | (0x00 << 8) | 0x00, |
| 66 |
(0x00 << 16) | (0xAA << 8) | 0x00, |
| 67 |
(0xAA << 16) | (0x55 << 8) | 0x00, |
| 68 |
(0x00 << 16) | (0x00 << 8) | 0xAA, |
| 69 |
(0xAA << 16) | (0x00 << 8) | 0xAA, |
| 70 |
(0x00 << 16) | (0xAA << 8) | 0xAA, |
| 71 |
(0xAA << 16) | (0xAA << 8) | 0xAA, |
| 72 |
(0x55 << 16) | (0x55 << 8) | 0x55, |
| 73 |
(0xFF << 16) | (0x55 << 8) | 0x55, |
| 74 |
(0x55 << 16) | (0xFF << 8) | 0x55, |
| 75 |
(0xFF << 16) | (0xFF << 8) | 0x55, |
| 76 |
(0x55 << 16) | (0x55 << 8) | 0xFF, |
| 77 |
(0xFF << 16) | (0x55 << 8) | 0xFF, |
| 78 |
(0x55 << 16) | (0xFF << 8) | 0xFF, |
| 79 |
(0xFF << 16) | (0xFF << 8) | 0xFF, |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
static unsigned long dcaddr; |
| 85 |
static unsigned long vgaddr; |
| 86 |
static unsigned long gpaddr; |
| 87 |
static unsigned long fbaddr; |
| 88 |
|
| 89 |
#define DC (phys_to_virt(dcaddr)) |
| 90 |
#define VG (phys_to_virt(vgaddr)) |
| 91 |
#define GP (phys_to_virt(gpaddr)) |
| 92 |
#define FB ((unsigned char *) phys_to_virt(fbaddr)) |
| 93 |
|
| 94 |
static void init_video_mode(void) |
| 95 |
{ |
| 96 |
unsigned int lo, hi, val; |
| 97 |
int i; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
rdmsr(0x4c000015, lo, hi); |
| 102 |
|
| 103 |
hi = vga_mode.pll; |
| 104 |
|
| 105 |
lo &= ~0x1008000; |
| 106 |
lo |= 0x01; |
| 107 |
|
| 108 |
wrmsr(0x4c000015, lo, hi); |
| 109 |
udelay(100); |
| 110 |
|
| 111 |
for(i = 0; i < 1000; i++) { |
| 112 |
rdmsr(0x4c000015, lo, hi); |
| 113 |
if (lo & 0x2000000) |
| 114 |
break; |
| 115 |
} |
| 116 |
|
| 117 |
lo &= ~0x01; |
| 118 |
wrmsr(0x4c000015, lo, hi); |
| 119 |
|
| 120 |
rdmsr(0x48002001, lo, hi); |
| 121 |
lo &= ~0x38; |
| 122 |
wrmsr(0x48002001, lo, hi); |
| 123 |
|
| 124 |
writel(0x4758, DC + 0x00); |
| 125 |
|
| 126 |
val = readl(DC + 0x00); |
| 127 |
|
| 128 |
writel(0, DC + 0x10); |
| 129 |
writel(0, DC + 0x14); |
| 130 |
writel(0, DC + 0x18); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
val = readl(DC + 0xD4); |
| 135 |
|
| 136 |
writel((0x4000 << 16) | 0x4000, DC + 0x90); |
| 137 |
writel(0, DC + 0x94); |
| 138 |
writel(val & ~0xf3040000, DC + 0xD4); |
| 139 |
|
| 140 |
|
| 141 |
writel(vga_mode.hactive * vga_mode.vactive | 0x01, DC + 0x2C); |
| 142 |
|
| 143 |
val = readl(DC + 0x88); |
| 144 |
writel(val & ~0xC00, DC + 0x88); |
| 145 |
writel(0, DC + 0x8C); |
| 146 |
|
| 147 |
|
| 148 |
writel(vga_mode.hactive >> 3, DC + 0x34); |
| 149 |
writel((vga_mode.hactive + 7) >> 3, DC + 0x30); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
lo = 0xC0; |
| 154 |
wrmsr(0x80000011, lo, hi); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
writel((vga_mode.hactive - 1) | ((vga_mode.htotal - 1) << 16), |
| 159 |
DC + 0x40); |
| 160 |
|
| 161 |
writel((vga_mode.hblankstart - 1) | ((vga_mode.hblankend - 1) << 16), |
| 162 |
DC + 0x44); |
| 163 |
|
| 164 |
writel((vga_mode.hsyncstart - 1) | ((vga_mode.hsyncend - 1) << 16), |
| 165 |
DC + 0x48); |
| 166 |
|
| 167 |
writel((vga_mode.vactive - 1) | ((vga_mode.vtotal - 1) << 16), |
| 168 |
DC + 0x50); |
| 169 |
|
| 170 |
writel((vga_mode.vblankstart - 1) | ((vga_mode.vblankend - 1) << 16), |
| 171 |
DC + 0x54); |
| 172 |
|
| 173 |
writel((vga_mode.vsyncstart - 1) | ((vga_mode.vsyncend - 1) << 16), |
| 174 |
DC + 0x58); |
| 175 |
|
| 176 |
writel(((vga_mode.hactive - 1) << 16) | (vga_mode.vactive - 1), |
| 177 |
DC + 0x5C); |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
writel(0x290000F | vga_mode.synccfg, VG + 0x08); |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
val = readl(VG + 0x50); |
| 186 |
writel((val & ~0xC00) | 0x01, VG + 0x50); |
| 187 |
|
| 188 |
|
| 189 |
writel(fbaddr, DC + 0x84); |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
writel(0xB000059, DC + 0x08); |
| 194 |
writel(0, DC + 0x0C); |
| 195 |
writel(0x2B601, DC + 0x04); |
| 196 |
} |
| 197 |
|
| 198 |
static void geodelx_set_palette(int entry, unsigned int color) |
| 199 |
{ |
| 200 |
writel(entry, DC + 0x70); |
| 201 |
writel(color, DC + 0x74); |
| 202 |
} |
| 203 |
|
| 204 |
static void geodelx_scroll_up(void) |
| 205 |
{ |
| 206 |
unsigned char *dst = FB; |
| 207 |
unsigned char *src = FB + font_height * vga_mode.hactive; |
| 208 |
int y; |
| 209 |
|
| 210 |
for(y = 0; y < vga_mode.vactive - font_height; y++) { |
| 211 |
memcpy(dst, src, vga_mode.hactive); |
| 212 |
|
| 213 |
dst += vga_mode.hactive; |
| 214 |
src += vga_mode.hactive; |
| 215 |
} |
| 216 |
|
| 217 |
for(; y < vga_mode.vactive; y++) { |
| 218 |
memset(dst, 0, vga_mode.hactive); |
| 219 |
dst += vga_mode.hactive; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
static void geodelx_clear(void) |
| 224 |
{ |
| 225 |
int row; |
| 226 |
unsigned char *ptr = FB; |
| 227 |
|
| 228 |
for(row = 0; row < vga_mode.vactive; row++) { |
| 229 |
memset(ptr, 0, vga_mode.hactive); |
| 230 |
ptr += vga_mode.hactive; |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
static void geodelx_putc(u8 row, u8 col, unsigned int ch) |
| 235 |
{ |
| 236 |
unsigned char *dst; |
| 237 |
|
| 238 |
unsigned char bg = (ch >> 12) & 0xF; |
| 239 |
unsigned char fg = (ch >> 8) & 0xF; |
| 240 |
|
| 241 |
int x, y; |
| 242 |
|
| 243 |
dst = FB + ((row * font_height) * vga_mode.hactive); |
| 244 |
dst += (col * font_width); |
| 245 |
|
| 246 |
for(y = 0; y < font_height; y++) { |
| 247 |
|
| 248 |
for(x = font_width - 1; x >= 0; x--) |
| 249 |
dst[font_width - x] = font_glyph_filled(ch, x, y) ? |
| 250 |
fg : bg; |
| 251 |
|
| 252 |
dst += vga_mode.hactive; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
static int geodelx_init(void) |
| 257 |
{ |
| 258 |
pcidev_t dev; |
| 259 |
int i; |
| 260 |
|
| 261 |
if (!pci_find_device(0x1022, 0x2081, &dev)) |
| 262 |
return -1; |
| 263 |
|
| 264 |
fbaddr = pci_read_resource(dev, 0); |
| 265 |
gpaddr = pci_read_resource(dev, 1); |
| 266 |
dcaddr = pci_read_resource(dev, 2); |
| 267 |
vgaddr = pci_read_resource(dev, 3); |
| 268 |
|
| 269 |
font_init(vga_mode.hactive); |
| 270 |
|
| 271 |
init_video_mode(); |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
for(i = 0; i < ARRAY_SIZE(vga_colors); i++) { |
| 276 |
geodelx_set_palette(i, vga_colors[i]); |
| 277 |
} |
| 278 |
|
| 279 |
geodelx_clear(); |
| 280 |
|
| 281 |
return 0; |
| 282 |
} |
| 283 |
|
| 284 |
struct video_console geodelx_video_console = { |
| 285 |
.init = geodelx_init, |
| 286 |
.putc = geodelx_putc, |
| 287 |
.clear = geodelx_clear, |
| 288 |
.scroll_up = geodelx_scroll_up, |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
.columns = 80, |
| 295 |
.rows = 25 |
| 296 |
}; |