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 | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 29 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 30 | enum { |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 31 | PCIBIOS_CHECK = 0xb101, |
| 32 | PCIBIOS_FINDDEV = 0xb102, |
| 33 | PCIBIOS_READCONFBYTE = 0xb108, |
| 34 | PCIBIOS_READCONFWORD = 0xb109, |
| 35 | PCIBIOS_READCONFDWORD = 0xb10a, |
| 36 | PCIBIOS_WRITECONFBYTE = 0xb10b, |
| 37 | PCIBIOS_WRITECONFWORD = 0xb10c, |
| 38 | PCIBIOS_WRITECONFDWORD = 0xb10d |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | // errors go in AH. Just set these up so that word assigns |
| 42 | // will work. KISS. |
| 43 | enum { |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 44 | PCIBIOS_SUCCESSFUL = 0x0000, |
| 45 | PCIBIOS_UNSUPPORTED = 0x8100, |
| 46 | PCIBIOS_BADVENDOR = 0x8300, |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 47 | PCIBIOS_NODEV = 0x8600, |
| 48 | PCIBIOS_BADREG = 0x8700 |
| 49 | }; |
| 50 | |
Maciej Pijanka | ea92185 | 2009-10-27 14:29:29 +0000 | [diff] [blame] | 51 | int int12_handler(struct eregs *regs); |
| 52 | int int1a_handler(struct eregs *regs); |
| 53 | int int15_handler(struct eregs *regs); |
| 54 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 55 | int int12_handler(struct eregs *regs) |
| 56 | { |
| 57 | regs->eax = 64 * 1024; |
| 58 | return 0; |
| 59 | } |
| 60 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 61 | #define PCI_CONFIG_SPACE_TYPE1 (1 << 0) |
| 62 | #define PCI_CONFIG_SPACE_TYPE2 (1 << 1) |
| 63 | #define PCI_SPECIAL_CYCLE_TYPE1 (1 << 4) |
| 64 | #define PCI_SPECIAL_CYCLE_TYPE2 (1 << 5) |
| 65 | |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 66 | int int1a_handler(struct eregs *regs) |
| 67 | { |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 68 | unsigned short func = (unsigned short)regs->eax; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 69 | int retval = 0; |
| 70 | unsigned short devid, vendorid, devfn; |
| 71 | /* Use short to get rid of gabage in upper half of 32-bit register */ |
| 72 | short devindex; |
| 73 | unsigned char bus; |
| 74 | struct device *dev; |
Stefan Reinauer | 46634e7 | 2009-11-05 12:44:50 +0000 | [diff] [blame] | 75 | u32 dword; |
| 76 | u16 word; |
| 77 | u8 byte, reg; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 78 | |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 79 | switch (func) { |
| 80 | case PCIBIOS_CHECK: |
| 81 | regs->edx = 0x20494350; /* ' ICP' */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 82 | regs->eax &= 0xffff0000; /* Clear AH / AL */ |
| 83 | regs->eax |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1; |
| 84 | // last bus in the system. Hard code to 255 for now. |
| 85 | // dev_enumerate() does not seem to tell us (publically) |
| 86 | regs->ecx = 0xff; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 87 | regs->edi = 0x00000000; /* protected mode entry */ |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 88 | retval = 0; |
| 89 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 90 | case PCIBIOS_FINDDEV: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 91 | devid = regs->ecx; |
| 92 | vendorid = regs->edx; |
| 93 | devindex = regs->esi; |
| 94 | dev = 0; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 95 | while ((dev = dev_find_device(vendorid, devid, dev))) { |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 96 | if (devindex <= 0) |
| 97 | break; |
| 98 | devindex--; |
| 99 | } |
| 100 | if (dev) { |
| 101 | unsigned short busdevfn; |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 102 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 103 | regs->eax |= PCIBIOS_SUCCESSFUL; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 104 | // busnum is an unsigned char; |
| 105 | // devfn is an int, so we mask it off. |
| 106 | busdevfn = (dev->bus->secondary << 8) |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 107 | | (dev->path.pci.devfn & 0xff); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 108 | printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn); |
| 109 | regs->ebx = busdevfn; |
| 110 | retval = 0; |
| 111 | } else { |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 112 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 113 | regs->eax |= PCIBIOS_NODEV; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 114 | retval = -1; |
| 115 | } |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 116 | break; |
| 117 | case PCIBIOS_READCONFDWORD: |
| 118 | case PCIBIOS_READCONFWORD: |
| 119 | case PCIBIOS_READCONFBYTE: |
| 120 | case PCIBIOS_WRITECONFDWORD: |
| 121 | case PCIBIOS_WRITECONFWORD: |
| 122 | case PCIBIOS_WRITECONFBYTE: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 123 | devfn = regs->ebx & 0xff; |
| 124 | bus = regs->ebx >> 8; |
| 125 | reg = regs->edi; |
| 126 | dev = dev_find_slot(bus, devfn); |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 127 | if (!dev) { |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 128 | 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] | 129 | // Or are we supposed to return PCIBIOS_NODEV? |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 130 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 131 | regs->eax |= PCIBIOS_BADREG; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 132 | retval = -1; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 133 | return retval; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 134 | } |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 135 | switch (func) { |
| 136 | case PCIBIOS_READCONFBYTE: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 137 | byte = pci_read_config8(dev, reg); |
| 138 | regs->ecx = byte; |
| 139 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 140 | case PCIBIOS_READCONFWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 141 | word = pci_read_config16(dev, reg); |
| 142 | regs->ecx = word; |
| 143 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 144 | case PCIBIOS_READCONFDWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 145 | dword = pci_read_config32(dev, reg); |
| 146 | regs->ecx = dword; |
| 147 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 148 | case PCIBIOS_WRITECONFBYTE: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 149 | byte = regs->ecx; |
| 150 | pci_write_config8(dev, reg, byte); |
| 151 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 152 | case PCIBIOS_WRITECONFWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 153 | word = regs->ecx; |
| 154 | pci_write_config16(dev, reg, word); |
| 155 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 156 | case PCIBIOS_WRITECONFDWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 157 | dword = regs->ecx; |
| 158 | pci_write_config32(dev, reg, dword); |
| 159 | break; |
| 160 | } |
| 161 | |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 162 | #if CONFIG_REALMODE_DEBUG |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 163 | printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n", |
| 164 | func, bus, devfn, reg, regs->ecx); |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame] | 165 | #endif |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 166 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 167 | regs->eax |= PCIBIOS_SUCCESSFUL; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 168 | retval = 0; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 169 | break; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 170 | default: |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 171 | printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func); |
Myles Watson | fe09fd1 | 2010-09-07 23:27:59 +0000 | [diff] [blame] | 172 | regs->eax &= 0xffff00ff; /* Clear AH */ |
| 173 | regs->eax |= PCIBIOS_UNSUPPORTED; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 174 | retval = -1; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 175 | break; |
| 176 | } |
| 177 | |
| 178 | return retval; |
| 179 | } |
| 180 | |
| 181 | int int15_handler(struct eregs *regs) |
| 182 | { |
| 183 | int res = -1; |
| 184 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 185 | /* This int15 handler is Intel IGD. specific. Other chipsets need other |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 186 | * handlers. The right way to do this is to move this handler code into |
| 187 | * the mainboard or northbridge code. |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 188 | * TODO: completely move to mainboards / chipsets. |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 189 | */ |
| 190 | switch (regs->eax & 0xffff) { |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 191 | /* And now Intel IGD code */ |
Stefan Reinauer | 074356e | 2009-10-25 19:50:47 +0000 | [diff] [blame] | 192 | #define BOOT_DISPLAY_DEFAULT 0 |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 193 | #define BOOT_DISPLAY_CRT (1 << 0) |
| 194 | #define BOOT_DISPLAY_TV (1 << 1) |
| 195 | #define BOOT_DISPLAY_EFP (1 << 2) |
| 196 | #define BOOT_DISPLAY_LCD (1 << 3) |
| 197 | #define BOOT_DISPLAY_CRT2 (1 << 4) |
| 198 | #define BOOT_DISPLAY_TV2 (1 << 5) |
| 199 | #define BOOT_DISPLAY_EFP2 (1 << 6) |
| 200 | #define BOOT_DISPLAY_LCD2 (1 << 7) |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 201 | case 0x5f35: |
| 202 | regs->eax = 0x5f; |
Stefan Reinauer | 074356e | 2009-10-25 19:50:47 +0000 | [diff] [blame] | 203 | regs->ecx = BOOT_DISPLAY_DEFAULT; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 204 | res = 0; |
| 205 | break; |
| 206 | case 0x5f40: |
| 207 | regs->eax = 0x5f; |
| 208 | regs->ecx = 3; // This is mainboard specific |
| 209 | printk(BIOS_DEBUG, "DISPLAY=%x\n", regs->ecx); |
| 210 | res = 0; |
| 211 | break; |
| 212 | default: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 213 | printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n", |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 214 | regs->eax & 0xffff); |
| 215 | } |
| 216 | |
| 217 | return res; |
| 218 | } |
| 219 | |