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; |
| 102 | regs->eax = 0; |
| 103 | // busnum is an unsigned char; |
| 104 | // devfn is an int, so we mask it off. |
| 105 | busdevfn = (dev->bus->secondary << 8) |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 106 | | (dev->path.pci.devfn & 0xff); |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 107 | printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn); |
| 108 | regs->ebx = busdevfn; |
| 109 | retval = 0; |
| 110 | } else { |
| 111 | regs->eax = PCIBIOS_NODEV; |
| 112 | retval = -1; |
| 113 | } |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 114 | break; |
| 115 | case PCIBIOS_READCONFDWORD: |
| 116 | case PCIBIOS_READCONFWORD: |
| 117 | case PCIBIOS_READCONFBYTE: |
| 118 | case PCIBIOS_WRITECONFDWORD: |
| 119 | case PCIBIOS_WRITECONFWORD: |
| 120 | case PCIBIOS_WRITECONFBYTE: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 121 | devfn = regs->ebx & 0xff; |
| 122 | bus = regs->ebx >> 8; |
| 123 | reg = regs->edi; |
| 124 | dev = dev_find_slot(bus, devfn); |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 125 | if (!dev) { |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 126 | 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] | 127 | // Or are we supposed to return PCIBIOS_NODEV? |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 128 | regs->eax = PCIBIOS_BADREG; |
| 129 | retval = -1; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 130 | return retval; |
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) { |
| 133 | case PCIBIOS_READCONFBYTE: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 134 | byte = pci_read_config8(dev, reg); |
| 135 | regs->ecx = byte; |
| 136 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 137 | case PCIBIOS_READCONFWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 138 | word = pci_read_config16(dev, reg); |
| 139 | regs->ecx = word; |
| 140 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 141 | case PCIBIOS_READCONFDWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 142 | dword = pci_read_config32(dev, reg); |
| 143 | regs->ecx = dword; |
| 144 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 145 | case PCIBIOS_WRITECONFBYTE: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 146 | byte = regs->ecx; |
| 147 | pci_write_config8(dev, reg, byte); |
| 148 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 149 | case PCIBIOS_WRITECONFWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 150 | word = regs->ecx; |
| 151 | pci_write_config16(dev, reg, word); |
| 152 | break; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 153 | case PCIBIOS_WRITECONFDWORD: |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 154 | dword = regs->ecx; |
| 155 | pci_write_config32(dev, reg, dword); |
| 156 | break; |
| 157 | } |
| 158 | |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame^] | 159 | #if CONFIG_REALMODE_DEBUG |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 160 | printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n", |
| 161 | func, bus, devfn, reg, regs->ecx); |
Myles Watson | 6c9bc01 | 2010-09-07 22:30:15 +0000 | [diff] [blame^] | 162 | #endif |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 163 | regs->eax = 0; |
| 164 | retval = 0; |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 165 | break; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 166 | default: |
Mark Marshall | d08e69d | 2009-11-05 09:03:04 +0000 | [diff] [blame] | 167 | printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func); |
| 168 | retval = -1; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 169 | break; |
| 170 | } |
| 171 | |
| 172 | return retval; |
| 173 | } |
| 174 | |
| 175 | int int15_handler(struct eregs *regs) |
| 176 | { |
| 177 | int res = -1; |
| 178 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 179 | /* This int15 handler is Intel IGD. specific. Other chipsets need other |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 180 | * handlers. The right way to do this is to move this handler code into |
| 181 | * the mainboard or northbridge code. |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 182 | * TODO: completely move to mainboards / chipsets. |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 183 | */ |
| 184 | switch (regs->eax & 0xffff) { |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 185 | /* And now Intel IGD code */ |
Stefan Reinauer | 074356e | 2009-10-25 19:50:47 +0000 | [diff] [blame] | 186 | #define BOOT_DISPLAY_DEFAULT 0 |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 187 | #define BOOT_DISPLAY_CRT (1 << 0) |
| 188 | #define BOOT_DISPLAY_TV (1 << 1) |
| 189 | #define BOOT_DISPLAY_EFP (1 << 2) |
| 190 | #define BOOT_DISPLAY_LCD (1 << 3) |
| 191 | #define BOOT_DISPLAY_CRT2 (1 << 4) |
| 192 | #define BOOT_DISPLAY_TV2 (1 << 5) |
| 193 | #define BOOT_DISPLAY_EFP2 (1 << 6) |
| 194 | #define BOOT_DISPLAY_LCD2 (1 << 7) |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 195 | case 0x5f35: |
| 196 | regs->eax = 0x5f; |
Stefan Reinauer | 074356e | 2009-10-25 19:50:47 +0000 | [diff] [blame] | 197 | regs->ecx = BOOT_DISPLAY_DEFAULT; |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 198 | res = 0; |
| 199 | break; |
| 200 | case 0x5f40: |
| 201 | regs->eax = 0x5f; |
| 202 | regs->ecx = 3; // This is mainboard specific |
| 203 | printk(BIOS_DEBUG, "DISPLAY=%x\n", regs->ecx); |
| 204 | res = 0; |
| 205 | break; |
| 206 | default: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 207 | printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n", |
Stefan Reinauer | 38cd29e | 2009-08-11 21:28:25 +0000 | [diff] [blame] | 208 | regs->eax & 0xffff); |
| 209 | } |
| 210 | |
| 211 | return res; |
| 212 | } |
| 213 | |