blob: 05cdd4a0c2a51e575e77b92c6c173f522b49d7aa [file] [log] [blame]
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2001 Ronald G. Minnich
5 * Copyright (C) 2005 Nick.Barker9@btinternet.com
6 * Copyright (C) 2007-2009 coresystems GmbH
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000016 */
17
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100018#include <arch/io.h>
19#include <arch/registers.h>
20#include <console/console.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000021#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <device/pci_ops.h>
24#include <string.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100025
Patrick Georgi199b09c2012-11-22 12:46:12 +010026/* we use x86emu's register file representation */
27#include <x86emu/regs.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000028
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100029#include "x86.h"
30
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000031// errors go in AH. Just set these up so that word assigns
32// will work. KISS.
33enum {
Mark Marshalld08e69d2009-11-05 09:03:04 +000034 PCIBIOS_SUCCESSFUL = 0x0000,
35 PCIBIOS_UNSUPPORTED = 0x8100,
36 PCIBIOS_BADVENDOR = 0x8300,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000037 PCIBIOS_NODEV = 0x8600,
38 PCIBIOS_BADREG = 0x8700
39};
40
Patrick Georgi199b09c2012-11-22 12:46:12 +010041int int10_handler(void)
Stefan Reinauer216fa462011-10-12 14:25:07 -070042{
Patrick Georgi503af722012-11-22 10:48:18 +010043 int res=0;
Stefan Reinauer216fa462011-10-12 14:25:07 -070044 static u8 cursor_row=0, cursor_col=0;
Patrick Georgi199b09c2012-11-22 12:46:12 +010045 switch((X86_EAX & 0xff00)>>8) {
Stefan Reinauer216fa462011-10-12 14:25:07 -070046 case 0x01: // Set cursor shape
Patrick Georgi503af722012-11-22 10:48:18 +010047 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070048 break;
49 case 0x02: // Set cursor position
Patrick Georgi199b09c2012-11-22 12:46:12 +010050 if (cursor_row != ((X86_EDX >> 8) & 0xff) ||
51 cursor_col >= (X86_EDX & 0xff)) {
Stefan Reinauer216fa462011-10-12 14:25:07 -070052 printk(BIOS_INFO, "\n");
53 }
Patrick Georgi199b09c2012-11-22 12:46:12 +010054 cursor_row = (X86_EDX >> 8) & 0xff;
55 cursor_col = X86_EDX & 0xff;
Patrick Georgi503af722012-11-22 10:48:18 +010056 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070057 break;
58 case 0x03: // Get cursor position
Patrick Georgi199b09c2012-11-22 12:46:12 +010059 X86_EAX &= 0x00ff;
60 X86_ECX = 0x0607;
61 X86_EDX = (cursor_row << 8) | cursor_col;
Patrick Georgi503af722012-11-22 10:48:18 +010062 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070063 break;
64 case 0x06: // Scroll up
65 printk(BIOS_INFO, "\n");
Patrick Georgi503af722012-11-22 10:48:18 +010066 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070067 break;
68 case 0x08: // Get Character and Mode at Cursor Position
Patrick Georgi199b09c2012-11-22 12:46:12 +010069 X86_EAX = 0x0f00 | 'A'; // White on black 'A'
Patrick Georgi503af722012-11-22 10:48:18 +010070 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070071 break;
72 case 0x09: // Write Character and attribute
Stefan Reinauer20d9de32011-12-13 23:08:03 +010073 case 0x0e: // Write Character
Patrick Georgi199b09c2012-11-22 12:46:12 +010074 printk(BIOS_INFO, "%c", X86_EAX & 0xff);
Patrick Georgi503af722012-11-22 10:48:18 +010075 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070076 break;
77 case 0x0f: // Get video mode
Patrick Georgi199b09c2012-11-22 12:46:12 +010078 X86_EAX = 0x5002; //80x25
79 X86_EBX &= 0x00ff;
Patrick Georgi503af722012-11-22 10:48:18 +010080 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070081 break;
82 default:
83 printk(BIOS_WARNING, "Unknown INT10 function %04x!\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +010084 X86_EAX & 0xffff);
Stefan Reinauer216fa462011-10-12 14:25:07 -070085 break;
86 }
87 return res;
88}
Maciej Pijankaea921852009-10-27 14:29:29 +000089
Patrick Georgi199b09c2012-11-22 12:46:12 +010090int int12_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000091{
Patrick Georgi199b09c2012-11-22 12:46:12 +010092 X86_EAX = 64 * 1024;
Patrick Georgi503af722012-11-22 10:48:18 +010093 return 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000094}
95
Patrick Georgi199b09c2012-11-22 12:46:12 +010096int int16_handler(void)
Stefan Reinauer216fa462011-10-12 14:25:07 -070097{
Patrick Georgi503af722012-11-22 10:48:18 +010098 int res=0;
Patrick Georgi199b09c2012-11-22 12:46:12 +010099 switch((X86_EAX & 0xff00)>>8) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700100 case 0x00: // Check for Keystroke
Patrick Georgi199b09c2012-11-22 12:46:12 +0100101 X86_EAX = 0x6120; // Space Bar, Space
Patrick Georgi503af722012-11-22 10:48:18 +0100102 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700103 break;
104 case 0x01: // Check for Keystroke
Patrick Georgi199b09c2012-11-22 12:46:12 +0100105 X86_EFLAGS |= 1<<6; // Zero Flag set (no key available)
Patrick Georgi503af722012-11-22 10:48:18 +0100106 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700107 break;
108 default:
109 printk(BIOS_WARNING, "Unknown INT16 function %04x!\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100110 X86_EAX & 0xffff);
Stefan Reinauer216fa462011-10-12 14:25:07 -0700111 break;
112 }
113 return res;
114}
115
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000116#define PCI_CONFIG_SPACE_TYPE1 (1 << 0)
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000117#define PCI_SPECIAL_CYCLE_TYPE1 (1 << 4)
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000118
Patrick Georgi199b09c2012-11-22 12:46:12 +0100119int int1a_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000120{
Patrick Georgi199b09c2012-11-22 12:46:12 +0100121 unsigned short func = (unsigned short)X86_EAX;
Patrick Georgi503af722012-11-22 10:48:18 +0100122 int retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000123 unsigned short devid, vendorid, devfn;
Martin Roth63373ed2013-07-08 16:24:19 -0600124 /* Use short to get rid of garbage in upper half of 32-bit register */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000125 short devindex;
126 unsigned char bus;
127 struct device *dev;
Stefan Reinauer46634e72009-11-05 12:44:50 +0000128 u32 dword;
129 u16 word;
130 u8 byte, reg;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000131
Mark Marshalld08e69d2009-11-05 09:03:04 +0000132 switch (func) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700133 case 0xb101: /* PCIBIOS Check */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100134 X86_EDX = 0x20494350; /* ' ICP' */
135 X86_EAX &= 0xffff0000; /* Clear AH / AL */
136 X86_EAX |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1;
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000137 // last bus in the system. Hard code to 255 for now.
Martin Roth63373ed2013-07-08 16:24:19 -0600138 // dev_enumerate() does not seem to tell us (publicly)
Patrick Georgi199b09c2012-11-22 12:46:12 +0100139 X86_ECX = 0xff;
140 X86_EDI = 0x00000000; /* protected mode entry */
Patrick Georgi503af722012-11-22 10:48:18 +0100141 retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000142 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700143 case 0xb102: /* Find Device */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100144 devid = X86_ECX;
145 vendorid = X86_EDX;
146 devindex = X86_ESI;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000147 dev = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000148 while ((dev = dev_find_device(vendorid, devid, dev))) {
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000149 if (devindex <= 0)
150 break;
151 devindex--;
152 }
153 if (dev) {
154 unsigned short busdevfn;
Patrick Georgi199b09c2012-11-22 12:46:12 +0100155 X86_EAX &= 0xffff00ff; /* Clear AH */
156 X86_EAX |= PCIBIOS_SUCCESSFUL;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000157 // busnum is an unsigned char;
158 // devfn is an int, so we mask it off.
159 busdevfn = (dev->bus->secondary << 8)
Mark Marshalld08e69d2009-11-05 09:03:04 +0000160 | (dev->path.pci.devfn & 0xff);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000161 printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100162 X86_EBX = busdevfn;
Patrick Georgi503af722012-11-22 10:48:18 +0100163 retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000164 } else {
Patrick Georgi199b09c2012-11-22 12:46:12 +0100165 X86_EAX &= 0xffff00ff; /* Clear AH */
166 X86_EAX |= PCIBIOS_NODEV;
Patrick Georgi503af722012-11-22 10:48:18 +0100167 retval = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000168 }
Mark Marshalld08e69d2009-11-05 09:03:04 +0000169 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700170 case 0xb10a: /* Read Config Dword */
171 case 0xb109: /* Read Config Word */
172 case 0xb108: /* Read Config Byte */
173 case 0xb10d: /* Write Config Dword */
174 case 0xb10c: /* Write Config Word */
175 case 0xb10b: /* Write Config Byte */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100176 devfn = X86_EBX & 0xff;
177 bus = X86_EBX >> 8;
178 reg = X86_EDI;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000179 dev = dev_find_slot(bus, devfn);
Mark Marshalld08e69d2009-11-05 09:03:04 +0000180 if (!dev) {
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000181 printk(BIOS_DEBUG, "0x%x: BAD DEVICE bus %d devfn 0x%x\n", func, bus, devfn);
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000182 // Or are we supposed to return PCIBIOS_NODEV?
Patrick Georgi199b09c2012-11-22 12:46:12 +0100183 X86_EAX &= 0xffff00ff; /* Clear AH */
184 X86_EAX |= PCIBIOS_BADREG;
Patrick Georgi503af722012-11-22 10:48:18 +0100185 retval = 0;
Mark Marshalld08e69d2009-11-05 09:03:04 +0000186 return retval;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000187 }
Mark Marshalld08e69d2009-11-05 09:03:04 +0000188 switch (func) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700189 case 0xb108: /* Read Config Byte */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000190 byte = pci_read_config8(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100191 X86_ECX = byte;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000192 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700193 case 0xb109: /* Read Config Word */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000194 word = pci_read_config16(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100195 X86_ECX = word;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000196 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700197 case 0xb10a: /* Read Config Dword */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000198 dword = pci_read_config32(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100199 X86_ECX = dword;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000200 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700201 case 0xb10b: /* Write Config Byte */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100202 byte = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000203 pci_write_config8(dev, reg, byte);
204 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700205 case 0xb10c: /* Write Config Word */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100206 word = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000207 pci_write_config16(dev, reg, word);
208 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700209 case 0xb10d: /* Write Config Dword */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100210 dword = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000211 pci_write_config32(dev, reg, dword);
212 break;
213 }
214
Myles Watson6c9bc012010-09-07 22:30:15 +0000215#if CONFIG_REALMODE_DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000216 printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100217 func, bus, devfn, reg, X86_ECX);
Myles Watson6c9bc012010-09-07 22:30:15 +0000218#endif
Patrick Georgi199b09c2012-11-22 12:46:12 +0100219 X86_EAX &= 0xffff00ff; /* Clear AH */
220 X86_EAX |= PCIBIOS_SUCCESSFUL;
Patrick Georgi503af722012-11-22 10:48:18 +0100221 retval = 1;
Mark Marshalld08e69d2009-11-05 09:03:04 +0000222 break;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000223 default:
Mark Marshalld08e69d2009-11-05 09:03:04 +0000224 printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100225 X86_EAX &= 0xffff00ff; /* Clear AH */
226 X86_EAX |= PCIBIOS_UNSUPPORTED;
Patrick Georgi503af722012-11-22 10:48:18 +0100227 retval = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000228 break;
229 }
230
231 return retval;
232}