2 * This file is part of the coreboot project.
4 * Copyright (C) 2001 Ronald G. Minnich
5 * Copyright (C) 2005 Nick.Barker9@btinternet.com
6 * Copyright (C) 2007-2009 coresystems GmbH
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.
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.
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
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
26 #include <console/console.h>
28 #include <arch/registers.h>
31 // errors go in AH. Just set these up so that word assigns
34 PCIBIOS_SUCCESSFUL = 0x0000,
35 PCIBIOS_UNSUPPORTED = 0x8100,
36 PCIBIOS_BADVENDOR = 0x8300,
37 PCIBIOS_NODEV = 0x8600,
38 PCIBIOS_BADREG = 0x8700
41 int int10_handler(struct eregs *regs)
44 static u8 cursor_row=0, cursor_col=0;
45 switch((regs->eax & 0xff00)>>8) {
46 case 0x01: // Set cursor shape
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");
54 cursor_row = (regs->edx >> 8) & 0xff;
55 cursor_col = regs->edx & 0xff;
58 case 0x03: // Get cursor position
61 regs->edx = (cursor_row << 8) | cursor_col;
64 case 0x06: // Scroll up
65 printk(BIOS_INFO, "\n");
68 case 0x08: // Get Character and Mode at Cursor Position
69 regs->eax = 0x0f00 | 'A'; // White on black 'A'
72 case 0x09: // Write Character and attribute
73 case 0x0e: // Write Character
74 printk(BIOS_INFO, "%c", regs->eax & 0xff);
77 case 0x0f: // Get video mode
78 regs->eax = 0x5002; //80x25
83 printk(BIOS_WARNING, "Unknown INT10 function %04x!\n",
90 int int12_handler(struct eregs *regs)
92 regs->eax = 64 * 1024;
96 int int16_handler(struct eregs *regs)
99 switch((regs->eax & 0xff00)>>8) {
100 case 0x00: // Check for Keystroke
101 regs->eax = 0x6120; // Space Bar, Space
104 case 0x01: // Check for Keystroke
105 regs->eflags |= 1<<6; // Zero Flag set (no key available)
109 printk(BIOS_WARNING, "Unknown INT16 function %04x!\n",
116 #define PCI_CONFIG_SPACE_TYPE1 (1 << 0)
117 #define PCI_CONFIG_SPACE_TYPE2 (1 << 1)
118 #define PCI_SPECIAL_CYCLE_TYPE1 (1 << 4)
119 #define PCI_SPECIAL_CYCLE_TYPE2 (1 << 5)
121 int int1a_handler(struct eregs *regs)
123 unsigned short func = (unsigned short)regs->eax;
125 unsigned short devid, vendorid, devfn;
126 /* Use short to get rid of gabage in upper half of 32-bit register */
135 case 0xb101: /* PCIBIOS Check */
136 regs->edx = 0x20494350; /* ' ICP' */
137 regs->eax &= 0xffff0000; /* Clear AH / AL */
138 regs->eax |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1;
139 // last bus in the system. Hard code to 255 for now.
140 // dev_enumerate() does not seem to tell us (publically)
142 regs->edi = 0x00000000; /* protected mode entry */
145 case 0xb102: /* Find Device */
147 vendorid = regs->edx;
148 devindex = regs->esi;
150 while ((dev = dev_find_device(vendorid, devid, dev))) {
156 unsigned short busdevfn;
157 regs->eax &= 0xffff00ff; /* Clear AH */
158 regs->eax |= PCIBIOS_SUCCESSFUL;
159 // busnum is an unsigned char;
160 // devfn is an int, so we mask it off.
161 busdevfn = (dev->bus->secondary << 8)
162 | (dev->path.pci.devfn & 0xff);
163 printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn);
164 regs->ebx = busdevfn;
167 regs->eax &= 0xffff00ff; /* Clear AH */
168 regs->eax |= PCIBIOS_NODEV;
172 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 */
178 devfn = regs->ebx & 0xff;
179 bus = regs->ebx >> 8;
181 dev = dev_find_slot(bus, devfn);
183 printk(BIOS_DEBUG, "0x%x: BAD DEVICE bus %d devfn 0x%x\n", func, bus, devfn);
184 // Or are we supposed to return PCIBIOS_NODEV?
185 regs->eax &= 0xffff00ff; /* Clear AH */
186 regs->eax |= PCIBIOS_BADREG;
191 case 0xb108: /* Read Config Byte */
192 byte = pci_read_config8(dev, reg);
195 case 0xb109: /* Read Config Word */
196 word = pci_read_config16(dev, reg);
199 case 0xb10a: /* Read Config Dword */
200 dword = pci_read_config32(dev, reg);
203 case 0xb10b: /* Write Config Byte */
205 pci_write_config8(dev, reg, byte);
207 case 0xb10c: /* Write Config Word */
209 pci_write_config16(dev, reg, word);
211 case 0xb10d: /* Write Config Dword */
213 pci_write_config32(dev, reg, dword);
217 #if CONFIG_REALMODE_DEBUG
218 printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n",
219 func, bus, devfn, reg, regs->ecx);
221 regs->eax &= 0xffff00ff; /* Clear AH */
222 regs->eax |= PCIBIOS_SUCCESSFUL;
226 printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func);
227 regs->eax &= 0xffff00ff; /* Clear AH */
228 regs->eax |= PCIBIOS_UNSUPPORTED;