Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 1 | /* |
| 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 Reinauer | 6c641ee | 2009-09-23 21:52:45 +0000 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pci_ids.h> |
| 24 | #include <device/pci_ops.h> |
| 25 | #include <string.h> |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 26 | #include <console/console.h> |
| 27 | #include <arch/io.h> |
Stefan Reinauer | 42dc721 | 2009-10-24 00:47:07 +0000 | [diff] [blame] | 28 | #include <arch/registers.h> |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 29 | #include "x86.h" |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 30 | |
| 31 | // errors go in AH. Just set these up so that word assigns |
| 32 | // will work. KISS. |
| 33 | enum { |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 34 | PCIBIOS_SUCCESSFUL = 0x0000, |
| 35 | PCIBIOS_UNSUPPORTED = 0x8100, |
| 36 | PCIBIOS_BADVENDOR = 0x8300, |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 37 | PCIBIOS_NODEV = 0x8600, |
| 38 | PCIBIOS_BADREG = 0x8700 |
| 39 | }; |
| 40 | |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 41 | int int10_handler(struct eregs *regs) |
| 42 | { |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 43 | int res=0; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 44 | static u8 cursor_row=0, cursor_col=0; |
| 45 | switch((regs->eax & 0xff00)>>8) { |
| 46 | case 0x01: // Set cursor shape |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 47 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 48 | 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 Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 56 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 57 | break; |
| 58 | case 0x03: // Get cursor position |
| 59 | regs->eax &= 0x00ff; |
| 60 | regs->ecx = 0x0607; |
| 61 | regs->edx = (cursor_row << 8) | cursor_col; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 62 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 63 | break; |
| 64 | case 0x06: // Scroll up |
| 65 | printk(BIOS_INFO, "\n"); |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 66 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 67 | break; |
| 68 | case 0x08: // Get Character and Mode at Cursor Position |
| 69 | regs->eax = 0x0f00 | 'A'; // White on black 'A' |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 70 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 71 | break; |
| 72 | case 0x09: // Write Character and attribute |
Stefan Reinauer | 20d9de3 | 2011-12-13 23:08:03 +0100 | [diff] [blame] | 73 | case 0x0e: // Write Character |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 74 | printk(BIOS_INFO, "%c", regs->eax & 0xff); |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 75 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 76 | break; |
| 77 | case 0x0f: // Get video mode |
| 78 | regs->eax = 0x5002; //80x25 |
| 79 | regs->ebx &= 0x00ff; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 80 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 81 | break; |
| 82 | default: |
| 83 | printk(BIOS_WARNING, "Unknown INT10 function %04x!\n", |
| 84 | regs->eax & 0xffff); |
| 85 | break; |
| 86 | } |
| 87 | return res; |
| 88 | } |
Maciej Pijanka | ea92185 | 2009-10-27 14:29:29 +0000 | [diff] [blame] | 89 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 90 | int int12_handler(struct eregs *regs) |
| 91 | { |
| 92 | regs->eax = 64 * 1024; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 93 | return 1; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 96 | int int16_handler(struct eregs *regs) |
| 97 | { |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 98 | int res=0; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 99 | switch((regs->eax & 0xff00)>>8) { |
| 100 | case 0x00: // Check for Keystroke |
| 101 | regs->eax = 0x6120; // Space Bar, Space |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 102 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 103 | break; |
| 104 | case 0x01: // Check for Keystroke |
| 105 | regs->eflags |= 1<<6; // Zero Flag set (no key available) |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 106 | res = 1; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 107 | 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 Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 116 | #define PCI_CONFIG_SPACE_TYPE1 (1 << 0) |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 117 | #define PCI_SPECIAL_CYCLE_TYPE1 (1 << 4) |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 118 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 119 | int int1a_handler(struct eregs *regs) |
| 120 | { |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 121 | unsigned short func = (unsigned short)regs->eax; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 122 | int retval = 1; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 123 | 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 Reinauer | 46634e7 | 2009-11-05 12:44:50 +0000 | [diff] [blame] | 128 | u32 dword; |
| 129 | u16 word; |
| 130 | u8 byte, reg; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 131 | |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 132 | switch (func) { |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 133 | case 0xb101: /* PCIBIOS Check */ |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 134 | regs->edx = 0x20494350; /* ' ICP' */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 135 | 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 Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 140 | regs->edi = 0x00000000; /* protected mode entry */ |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 141 | retval = 1; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 142 | break; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 143 | case 0xb102: /* Find Device */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 144 | devid = regs->ecx; |
| 145 | vendorid = regs->edx; |
| 146 | devindex = regs->esi; |
| 147 | dev = 0; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 148 | while ((dev = dev_find_device(vendorid, devid, dev))) { |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 149 | if (devindex <= 0) |
| 150 | break; |
| 151 | devindex--; |
| 152 | } |
| 153 | if (dev) { |
| 154 | unsigned short busdevfn; |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 155 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 156 | regs->eax |= PCIBIOS_SUCCESSFUL; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 157 | // busnum is an unsigned char; |
| 158 | // devfn is an int, so we mask it off. |
| 159 | busdevfn = (dev->bus->secondary << 8) |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 160 | | (dev->path.pci.devfn & 0xff); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 161 | printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn); |
| 162 | regs->ebx = busdevfn; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 163 | retval = 1; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 164 | } else { |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 165 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 166 | regs->eax |= PCIBIOS_NODEV; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 167 | retval = 0; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 168 | } |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 169 | break; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 170 | 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 Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 176 | devfn = regs->ebx & 0xff; |
| 177 | bus = regs->ebx >> 8; |
| 178 | reg = regs->edi; |
| 179 | dev = dev_find_slot(bus, devfn); |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 180 | if (!dev) { |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 181 | printk(BIOS_DEBUG, "0x%x: BAD DEVICE bus %d devfn 0x%x\n", func, bus, devfn); |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 182 | // Or are we supposed to return PCIBIOS_NODEV? |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 183 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 184 | regs->eax |= PCIBIOS_BADREG; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 185 | retval = 0; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 186 | return retval; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 187 | } |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 188 | switch (func) { |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 189 | case 0xb108: /* Read Config Byte */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 190 | byte = pci_read_config8(dev, reg); |
| 191 | regs->ecx = byte; |
| 192 | break; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 193 | case 0xb109: /* Read Config Word */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 194 | word = pci_read_config16(dev, reg); |
| 195 | regs->ecx = word; |
| 196 | break; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 197 | case 0xb10a: /* Read Config Dword */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 198 | dword = pci_read_config32(dev, reg); |
| 199 | regs->ecx = dword; |
| 200 | break; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 201 | case 0xb10b: /* Write Config Byte */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 202 | byte = regs->ecx; |
| 203 | pci_write_config8(dev, reg, byte); |
| 204 | break; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 205 | case 0xb10c: /* Write Config Word */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 206 | word = regs->ecx; |
| 207 | pci_write_config16(dev, reg, word); |
| 208 | break; |
Stefan Reinauer | 216fa46 | 2011-10-12 14:25:07 -0700 | [diff] [blame] | 209 | case 0xb10d: /* Write Config Dword */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 210 | dword = regs->ecx; |
| 211 | pci_write_config32(dev, reg, dword); |
| 212 | break; |
| 213 | } |
| 214 | |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 215 | #if CONFIG_REALMODE_DEBUG |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 216 | 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 Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 218 | #endif |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 219 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 220 | regs->eax |= PCIBIOS_SUCCESSFUL; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 221 | retval = 1; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 222 | break; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 223 | default: |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 224 | printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func); |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 225 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 226 | regs->eax |= PCIBIOS_UNSUPPORTED; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame^] | 227 | retval = 0; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 228 | break; |
| 229 | } |
| 230 | |
| 231 | return retval; |
| 232 | } |
| 233 | |