blob: b4ff1357bf7454581ecfc292e703dce338458a5f [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"
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000030
31// 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
Stefan Reinauer216fa462011-10-12 14:25:07 -070041int int10_handler(struct eregs *regs)
42{
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;
45 switch((regs->eax & 0xff00)>>8) {
46 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
50 if (cursor_row != ((regs->edx >> 8) & 0xff) ||
51 cursor_col >= (regs->edx & 0xff)) {
52 printk(BIOS_INFO, "\n");
53 }
54 cursor_row = (regs->edx >> 8) & 0xff;
55 cursor_col = regs->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
59 regs->eax &= 0x00ff;
60 regs->ecx = 0x0607;
61 regs->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
69 regs->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
Stefan Reinauer216fa462011-10-12 14:25:07 -070074 printk(BIOS_INFO, "%c", regs->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
78 regs->eax = 0x5002; //80x25
79 regs->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",
84 regs->eax & 0xffff);
85 break;
86 }
87 return res;
88}
Maciej Pijankaea921852009-10-27 14:29:29 +000089
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000090int int12_handler(struct eregs *regs)
91{
92 regs->eax = 64 * 1024;
Patrick Georgi503af722012-11-22 10:48:18 +010093 return 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000094}
95
Stefan Reinauer216fa462011-10-12 14:25:07 -070096int int16_handler(struct eregs *regs)
97{
Patrick Georgi503af722012-11-22 10:48:18 +010098 int res=0;
Stefan Reinauer216fa462011-10-12 14:25:07 -070099 switch((regs->eax & 0xff00)>>8) {
100 case 0x00: // Check for Keystroke
101 regs->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
105 regs->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",
110 regs->eax & 0xffff);
111 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
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000119int int1a_handler(struct eregs *regs)
120{
Mark Marshalld08e69d2009-11-05 09:03:04 +0000121 unsigned short func = (unsigned short)regs->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;
124 /* Use short to get rid of gabage in upper half of 32-bit register */
125 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 */
Mark Marshalld08e69d2009-11-05 09:03:04 +0000134 regs->edx = 0x20494350; /* ' ICP' */
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000135 regs->eax &= 0xffff0000; /* Clear AH / AL */
136 regs->eax |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1;
137 // last bus in the system. Hard code to 255 for now.
138 // dev_enumerate() does not seem to tell us (publically)
139 regs->ecx = 0xff;
Mark Marshalld08e69d2009-11-05 09:03:04 +0000140 regs->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 */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000144 devid = regs->ecx;
145 vendorid = regs->edx;
146 devindex = regs->esi;
147 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;
Myles Watsonfe09fd12010-09-07 23:27:59 +0000155 regs->eax &= 0xffff00ff; /* Clear AH */
156 regs->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);
162 regs->ebx = busdevfn;
Patrick Georgi503af722012-11-22 10:48:18 +0100163 retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000164 } else {
Myles Watsonfe09fd12010-09-07 23:27:59 +0000165 regs->eax &= 0xffff00ff; /* Clear AH */
166 regs->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 */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000176 devfn = regs->ebx & 0xff;
177 bus = regs->ebx >> 8;
178 reg = regs->edi;
179 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?
Myles Watsonfe09fd12010-09-07 23:27:59 +0000183 regs->eax &= 0xffff00ff; /* Clear AH */
184 regs->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);
191 regs->ecx = byte;
192 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);
195 regs->ecx = word;
196 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);
199 regs->ecx = dword;
200 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700201 case 0xb10b: /* Write Config Byte */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000202 byte = regs->ecx;
203 pci_write_config8(dev, reg, byte);
204 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700205 case 0xb10c: /* Write Config Word */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000206 word = regs->ecx;
207 pci_write_config16(dev, reg, word);
208 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700209 case 0xb10d: /* Write Config Dword */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000210 dword = regs->ecx;
211 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",
217 func, bus, devfn, reg, regs->ecx);
Myles Watson6c9bc012010-09-07 22:30:15 +0000218#endif
Myles Watsonfe09fd12010-09-07 23:27:59 +0000219 regs->eax &= 0xffff00ff; /* Clear AH */
220 regs->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);
Myles Watsonfe09fd12010-09-07 23:27:59 +0000225 regs->eax &= 0xffff00ff; /* Clear AH */
226 regs->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}
233