blob: b3764f93b78238f62536e6ffa08b311752dfdda5 [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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Stefan Reinauer6c641ee2009-09-23 21:52:45 +000019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000020 */
21
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <device/pci_ops.h>
25#include <string.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000026#include <console/console.h>
27#include <arch/io.h>
Stefan Reinauer42dc7212009-10-24 00:47:07 +000028#include <arch/registers.h>
Stefan Reinauer216fa462011-10-12 14:25:07 -070029#include "x86.h"
Patrick Georgi199b09c2012-11-22 12:46:12 +010030/* we use x86emu's register file representation */
31#include <x86emu/regs.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000032
33// errors go in AH. Just set these up so that word assigns
34// will work. KISS.
35enum {
Mark Marshalld08e69d2009-11-05 09:03:04 +000036 PCIBIOS_SUCCESSFUL = 0x0000,
37 PCIBIOS_UNSUPPORTED = 0x8100,
38 PCIBIOS_BADVENDOR = 0x8300,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000039 PCIBIOS_NODEV = 0x8600,
40 PCIBIOS_BADREG = 0x8700
41};
42
Patrick Georgi199b09c2012-11-22 12:46:12 +010043int int10_handler(void)
Stefan Reinauer216fa462011-10-12 14:25:07 -070044{
Patrick Georgi503af722012-11-22 10:48:18 +010045 int res=0;
Stefan Reinauer216fa462011-10-12 14:25:07 -070046 static u8 cursor_row=0, cursor_col=0;
Patrick Georgi199b09c2012-11-22 12:46:12 +010047 switch((X86_EAX & 0xff00)>>8) {
Stefan Reinauer216fa462011-10-12 14:25:07 -070048 case 0x01: // Set cursor shape
Patrick Georgi503af722012-11-22 10:48:18 +010049 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070050 break;
51 case 0x02: // Set cursor position
Patrick Georgi199b09c2012-11-22 12:46:12 +010052 if (cursor_row != ((X86_EDX >> 8) & 0xff) ||
53 cursor_col >= (X86_EDX & 0xff)) {
Stefan Reinauer216fa462011-10-12 14:25:07 -070054 printk(BIOS_INFO, "\n");
55 }
Patrick Georgi199b09c2012-11-22 12:46:12 +010056 cursor_row = (X86_EDX >> 8) & 0xff;
57 cursor_col = X86_EDX & 0xff;
Patrick Georgi503af722012-11-22 10:48:18 +010058 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070059 break;
60 case 0x03: // Get cursor position
Patrick Georgi199b09c2012-11-22 12:46:12 +010061 X86_EAX &= 0x00ff;
62 X86_ECX = 0x0607;
63 X86_EDX = (cursor_row << 8) | cursor_col;
Patrick Georgi503af722012-11-22 10:48:18 +010064 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070065 break;
66 case 0x06: // Scroll up
67 printk(BIOS_INFO, "\n");
Patrick Georgi503af722012-11-22 10:48:18 +010068 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070069 break;
70 case 0x08: // Get Character and Mode at Cursor Position
Patrick Georgi199b09c2012-11-22 12:46:12 +010071 X86_EAX = 0x0f00 | 'A'; // White on black 'A'
Patrick Georgi503af722012-11-22 10:48:18 +010072 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070073 break;
74 case 0x09: // Write Character and attribute
Stefan Reinauer20d9de32011-12-13 23:08:03 +010075 case 0x0e: // Write Character
Patrick Georgi199b09c2012-11-22 12:46:12 +010076 printk(BIOS_INFO, "%c", X86_EAX & 0xff);
Patrick Georgi503af722012-11-22 10:48:18 +010077 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070078 break;
79 case 0x0f: // Get video mode
Patrick Georgi199b09c2012-11-22 12:46:12 +010080 X86_EAX = 0x5002; //80x25
81 X86_EBX &= 0x00ff;
Patrick Georgi503af722012-11-22 10:48:18 +010082 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070083 break;
84 default:
85 printk(BIOS_WARNING, "Unknown INT10 function %04x!\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +010086 X86_EAX & 0xffff);
Stefan Reinauer216fa462011-10-12 14:25:07 -070087 break;
88 }
89 return res;
90}
Maciej Pijankaea921852009-10-27 14:29:29 +000091
Patrick Georgi199b09c2012-11-22 12:46:12 +010092int int12_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000093{
Patrick Georgi199b09c2012-11-22 12:46:12 +010094 X86_EAX = 64 * 1024;
Patrick Georgi503af722012-11-22 10:48:18 +010095 return 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000096}
97
Patrick Georgi199b09c2012-11-22 12:46:12 +010098int int16_handler(void)
Stefan Reinauer216fa462011-10-12 14:25:07 -070099{
Patrick Georgi503af722012-11-22 10:48:18 +0100100 int res=0;
Patrick Georgi199b09c2012-11-22 12:46:12 +0100101 switch((X86_EAX & 0xff00)>>8) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700102 case 0x00: // Check for Keystroke
Patrick Georgi199b09c2012-11-22 12:46:12 +0100103 X86_EAX = 0x6120; // Space Bar, Space
Patrick Georgi503af722012-11-22 10:48:18 +0100104 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700105 break;
106 case 0x01: // Check for Keystroke
Patrick Georgi199b09c2012-11-22 12:46:12 +0100107 X86_EFLAGS |= 1<<6; // Zero Flag set (no key available)
Patrick Georgi503af722012-11-22 10:48:18 +0100108 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700109 break;
110 default:
111 printk(BIOS_WARNING, "Unknown INT16 function %04x!\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100112 X86_EAX & 0xffff);
Stefan Reinauer216fa462011-10-12 14:25:07 -0700113 break;
114 }
115 return res;
116}
117
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000118#define PCI_CONFIG_SPACE_TYPE1 (1 << 0)
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000119#define PCI_SPECIAL_CYCLE_TYPE1 (1 << 4)
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000120
Patrick Georgi199b09c2012-11-22 12:46:12 +0100121int int1a_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000122{
Patrick Georgi199b09c2012-11-22 12:46:12 +0100123 unsigned short func = (unsigned short)X86_EAX;
Patrick Georgi503af722012-11-22 10:48:18 +0100124 int retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000125 unsigned short devid, vendorid, devfn;
126 /* Use short to get rid of gabage in upper half of 32-bit register */
127 short devindex;
128 unsigned char bus;
129 struct device *dev;
Stefan Reinauer46634e72009-11-05 12:44:50 +0000130 u32 dword;
131 u16 word;
132 u8 byte, reg;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000133
Mark Marshalld08e69d2009-11-05 09:03:04 +0000134 switch (func) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700135 case 0xb101: /* PCIBIOS Check */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100136 X86_EDX = 0x20494350; /* ' ICP' */
137 X86_EAX &= 0xffff0000; /* Clear AH / AL */
138 X86_EAX |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1;
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000139 // last bus in the system. Hard code to 255 for now.
140 // dev_enumerate() does not seem to tell us (publically)
Patrick Georgi199b09c2012-11-22 12:46:12 +0100141 X86_ECX = 0xff;
142 X86_EDI = 0x00000000; /* protected mode entry */
Patrick Georgi503af722012-11-22 10:48:18 +0100143 retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000144 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700145 case 0xb102: /* Find Device */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100146 devid = X86_ECX;
147 vendorid = X86_EDX;
148 devindex = X86_ESI;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000149 dev = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000150 while ((dev = dev_find_device(vendorid, devid, dev))) {
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000151 if (devindex <= 0)
152 break;
153 devindex--;
154 }
155 if (dev) {
156 unsigned short busdevfn;
Patrick Georgi199b09c2012-11-22 12:46:12 +0100157 X86_EAX &= 0xffff00ff; /* Clear AH */
158 X86_EAX |= PCIBIOS_SUCCESSFUL;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000159 // busnum is an unsigned char;
160 // devfn is an int, so we mask it off.
161 busdevfn = (dev->bus->secondary << 8)
Mark Marshalld08e69d2009-11-05 09:03:04 +0000162 | (dev->path.pci.devfn & 0xff);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000163 printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100164 X86_EBX = busdevfn;
Patrick Georgi503af722012-11-22 10:48:18 +0100165 retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000166 } else {
Patrick Georgi199b09c2012-11-22 12:46:12 +0100167 X86_EAX &= 0xffff00ff; /* Clear AH */
168 X86_EAX |= PCIBIOS_NODEV;
Patrick Georgi503af722012-11-22 10:48:18 +0100169 retval = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000170 }
Mark Marshalld08e69d2009-11-05 09:03:04 +0000171 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700172 case 0xb10a: /* Read Config Dword */
173 case 0xb109: /* Read Config Word */
174 case 0xb108: /* Read Config Byte */
175 case 0xb10d: /* Write Config Dword */
176 case 0xb10c: /* Write Config Word */
177 case 0xb10b: /* Write Config Byte */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100178 devfn = X86_EBX & 0xff;
179 bus = X86_EBX >> 8;
180 reg = X86_EDI;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000181 dev = dev_find_slot(bus, devfn);
Mark Marshalld08e69d2009-11-05 09:03:04 +0000182 if (!dev) {
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000183 printk(BIOS_DEBUG, "0x%x: BAD DEVICE bus %d devfn 0x%x\n", func, bus, devfn);
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000184 // Or are we supposed to return PCIBIOS_NODEV?
Patrick Georgi199b09c2012-11-22 12:46:12 +0100185 X86_EAX &= 0xffff00ff; /* Clear AH */
186 X86_EAX |= PCIBIOS_BADREG;
Patrick Georgi503af722012-11-22 10:48:18 +0100187 retval = 0;
Mark Marshalld08e69d2009-11-05 09:03:04 +0000188 return retval;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000189 }
Mark Marshalld08e69d2009-11-05 09:03:04 +0000190 switch (func) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700191 case 0xb108: /* Read Config Byte */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000192 byte = pci_read_config8(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100193 X86_ECX = byte;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000194 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700195 case 0xb109: /* Read Config Word */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000196 word = pci_read_config16(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100197 X86_ECX = word;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000198 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700199 case 0xb10a: /* Read Config Dword */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000200 dword = pci_read_config32(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100201 X86_ECX = dword;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000202 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700203 case 0xb10b: /* Write Config Byte */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100204 byte = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000205 pci_write_config8(dev, reg, byte);
206 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700207 case 0xb10c: /* Write Config Word */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100208 word = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000209 pci_write_config16(dev, reg, word);
210 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700211 case 0xb10d: /* Write Config Dword */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100212 dword = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000213 pci_write_config32(dev, reg, dword);
214 break;
215 }
216
Myles Watson6c9bc012010-09-07 22:30:15 +0000217#if CONFIG_REALMODE_DEBUG
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000218 printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100219 func, bus, devfn, reg, X86_ECX);
Myles Watson6c9bc012010-09-07 22:30:15 +0000220#endif
Patrick Georgi199b09c2012-11-22 12:46:12 +0100221 X86_EAX &= 0xffff00ff; /* Clear AH */
222 X86_EAX |= PCIBIOS_SUCCESSFUL;
Patrick Georgi503af722012-11-22 10:48:18 +0100223 retval = 1;
Mark Marshalld08e69d2009-11-05 09:03:04 +0000224 break;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000225 default:
Mark Marshalld08e69d2009-11-05 09:03:04 +0000226 printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100227 X86_EAX &= 0xffff00ff; /* Clear AH */
228 X86_EAX |= PCIBIOS_UNSUPPORTED;
Patrick Georgi503af722012-11-22 10:48:18 +0100229 retval = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000230 break;
231 }
232
233 return retval;
234}
235