Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <pc80/mc146818rtc.h> |
| 26 | #include <pc80/isa-dma.h> |
| 27 | #include <pc80/i8259.h> |
| 28 | #include <arch/io.h> |
| 29 | #include <arch/ioapic.h> |
| 30 | #include <arch/acpi.h> |
| 31 | #include <cpu/cpu.h> |
Duncan Laurie | 800e950 | 2012-06-23 17:06:47 -0700 | [diff] [blame] | 32 | #include <elog.h> |
Vladimir Serbinenko | 35c0f43 | 2014-09-02 22:25:36 +0200 | [diff] [blame] | 33 | #include <arch/acpigen.h> |
| 34 | #include <drivers/intel/gma/i915.h> |
| 35 | #include <cbmem.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 36 | #include "pch.h" |
Vladimir Serbinenko | 35c0f43 | 2014-09-02 22:25:36 +0200 | [diff] [blame] | 37 | #include "nvs.h" |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 38 | |
| 39 | #define NMI_OFF 0 |
| 40 | |
| 41 | #define ENABLE_ACPI_MODE_IN_COREBOOT 0 |
| 42 | #define TEST_SMM_FLASH_LOCKDOWN 0 |
| 43 | |
| 44 | typedef struct southbridge_intel_bd82x6x_config config_t; |
| 45 | |
Paul Menzel | 9c50e6a | 2013-05-03 12:23:39 +0200 | [diff] [blame] | 46 | /** |
| 47 | * Set miscellanous static southbridge features. |
| 48 | * |
| 49 | * @param dev PCI device with I/O APIC control registers |
| 50 | */ |
| 51 | static void pch_enable_ioapic(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 52 | { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 53 | u32 reg32; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 54 | |
Paul Menzel | 9c50e6a | 2013-05-03 12:23:39 +0200 | [diff] [blame] | 55 | /* Enable ACPI I/O range decode */ |
| 56 | pci_write_config8(dev, ACPI_CNTL, ACPI_EN); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 57 | |
Paul Menzel | 9c50e6a | 2013-05-03 12:23:39 +0200 | [diff] [blame] | 58 | set_ioapic_id(IO_APIC_ADDR, 0x02); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 59 | |
| 60 | /* affirm full set of redirection table entries ("write once") */ |
Paul Menzel | 9c50e6a | 2013-05-03 12:23:39 +0200 | [diff] [blame] | 61 | reg32 = io_apic_read(IO_APIC_ADDR, 0x01); |
| 62 | io_apic_write(IO_APIC_ADDR, 0x01, reg32); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 63 | |
Paul Menzel | 9c50e6a | 2013-05-03 12:23:39 +0200 | [diff] [blame] | 64 | /* |
| 65 | * Select Boot Configuration register (0x03) and |
| 66 | * use Processor System Bus (0x01) to deliver interrupts. |
| 67 | */ |
| 68 | io_apic_write(IO_APIC_ADDR, 0x03, 0x01); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void pch_enable_serial_irqs(struct device *dev) |
| 72 | { |
| 73 | /* Set packet length and toggle silent mode bit for one frame. */ |
| 74 | pci_write_config8(dev, SERIRQ_CNTL, |
| 75 | (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 76 | #if !CONFIG_SERIRQ_CONTINUOUS_MODE |
| 77 | pci_write_config8(dev, SERIRQ_CNTL, |
| 78 | (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0)); |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 83 | * 0x00 - 0000 = Reserved |
| 84 | * 0x01 - 0001 = Reserved |
| 85 | * 0x02 - 0010 = Reserved |
| 86 | * 0x03 - 0011 = IRQ3 |
| 87 | * 0x04 - 0100 = IRQ4 |
| 88 | * 0x05 - 0101 = IRQ5 |
| 89 | * 0x06 - 0110 = IRQ6 |
| 90 | * 0x07 - 0111 = IRQ7 |
| 91 | * 0x08 - 1000 = Reserved |
| 92 | * 0x09 - 1001 = IRQ9 |
| 93 | * 0x0A - 1010 = IRQ10 |
| 94 | * 0x0B - 1011 = IRQ11 |
| 95 | * 0x0C - 1100 = IRQ12 |
| 96 | * 0x0D - 1101 = Reserved |
| 97 | * 0x0E - 1110 = IRQ14 |
| 98 | * 0x0F - 1111 = IRQ15 |
| 99 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 100 | * 0x80 - The PIRQ is not routed. |
| 101 | */ |
| 102 | |
| 103 | static void pch_pirq_init(device_t dev) |
| 104 | { |
| 105 | device_t irq_dev; |
| 106 | /* Get the chip configuration */ |
| 107 | config_t *config = dev->chip_info; |
| 108 | |
| 109 | pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing); |
| 110 | pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing); |
| 111 | pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing); |
| 112 | pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing); |
| 113 | |
| 114 | pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing); |
| 115 | pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing); |
| 116 | pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing); |
| 117 | pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing); |
| 118 | |
| 119 | /* Eric Biederman once said we should let the OS do this. |
| 120 | * I am not so sure anymore he was right. |
| 121 | */ |
| 122 | |
| 123 | for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 124 | u8 int_pin=0, int_line=0; |
| 125 | |
| 126 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 127 | continue; |
| 128 | |
| 129 | int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 130 | |
| 131 | switch (int_pin) { |
| 132 | case 1: /* INTA# */ int_line = config->pirqa_routing; break; |
| 133 | case 2: /* INTB# */ int_line = config->pirqb_routing; break; |
| 134 | case 3: /* INTC# */ int_line = config->pirqc_routing; break; |
| 135 | case 4: /* INTD# */ int_line = config->pirqd_routing; break; |
| 136 | } |
| 137 | |
| 138 | if (!int_line) |
| 139 | continue; |
| 140 | |
| 141 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | static void pch_gpi_routing(device_t dev) |
| 146 | { |
| 147 | /* Get the chip configuration */ |
| 148 | config_t *config = dev->chip_info; |
| 149 | u32 reg32 = 0; |
| 150 | |
| 151 | /* An array would be much nicer here, or some |
| 152 | * other method of doing this. |
| 153 | */ |
| 154 | reg32 |= (config->gpi0_routing & 0x03) << 0; |
| 155 | reg32 |= (config->gpi1_routing & 0x03) << 2; |
| 156 | reg32 |= (config->gpi2_routing & 0x03) << 4; |
| 157 | reg32 |= (config->gpi3_routing & 0x03) << 6; |
| 158 | reg32 |= (config->gpi4_routing & 0x03) << 8; |
| 159 | reg32 |= (config->gpi5_routing & 0x03) << 10; |
| 160 | reg32 |= (config->gpi6_routing & 0x03) << 12; |
| 161 | reg32 |= (config->gpi7_routing & 0x03) << 14; |
| 162 | reg32 |= (config->gpi8_routing & 0x03) << 16; |
| 163 | reg32 |= (config->gpi9_routing & 0x03) << 18; |
| 164 | reg32 |= (config->gpi10_routing & 0x03) << 20; |
| 165 | reg32 |= (config->gpi11_routing & 0x03) << 22; |
| 166 | reg32 |= (config->gpi12_routing & 0x03) << 24; |
| 167 | reg32 |= (config->gpi13_routing & 0x03) << 26; |
| 168 | reg32 |= (config->gpi14_routing & 0x03) << 28; |
| 169 | reg32 |= (config->gpi15_routing & 0x03) << 30; |
| 170 | |
| 171 | pci_write_config32(dev, 0xb8, reg32); |
| 172 | } |
| 173 | |
| 174 | static void pch_power_options(device_t dev) |
| 175 | { |
| 176 | u8 reg8; |
| 177 | u16 reg16, pmbase; |
| 178 | u32 reg32; |
| 179 | const char *state; |
| 180 | /* Get the chip configuration */ |
| 181 | config_t *config = dev->chip_info; |
| 182 | |
| 183 | int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL; |
| 184 | int nmi_option; |
| 185 | |
| 186 | /* Which state do we want to goto after g3 (power restored)? |
| 187 | * 0 == S0 Full On |
| 188 | * 1 == S5 Soft Off |
| 189 | * |
| 190 | * If the option is not existent (Laptops), use Kconfig setting. |
| 191 | */ |
| 192 | get_option(&pwr_on, "power_on_after_fail"); |
| 193 | |
| 194 | reg16 = pci_read_config16(dev, GEN_PMCON_3); |
| 195 | reg16 &= 0xfffe; |
| 196 | switch (pwr_on) { |
| 197 | case MAINBOARD_POWER_OFF: |
| 198 | reg16 |= 1; |
| 199 | state = "off"; |
| 200 | break; |
| 201 | case MAINBOARD_POWER_ON: |
| 202 | reg16 &= ~1; |
| 203 | state = "on"; |
| 204 | break; |
| 205 | case MAINBOARD_POWER_KEEP: |
| 206 | reg16 &= ~1; |
| 207 | state = "state keep"; |
| 208 | break; |
| 209 | default: |
| 210 | state = "undefined"; |
| 211 | } |
| 212 | |
| 213 | reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */ |
| 214 | reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */ |
| 215 | |
| 216 | reg16 &= ~(1 << 10); |
| 217 | reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */ |
| 218 | |
| 219 | reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */ |
| 220 | |
| 221 | pci_write_config16(dev, GEN_PMCON_3, reg16); |
| 222 | printk(BIOS_INFO, "Set power %s after power failure.\n", state); |
| 223 | |
| 224 | /* Set up NMI on errors. */ |
| 225 | reg8 = inb(0x61); |
| 226 | reg8 &= 0x0f; /* Higher Nibble must be 0 */ |
| 227 | reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */ |
| 228 | // reg8 &= ~(1 << 2); /* PCI SERR# Enable */ |
| 229 | reg8 |= (1 << 2); /* PCI SERR# Disable for now */ |
| 230 | outb(reg8, 0x61); |
| 231 | |
| 232 | reg8 = inb(0x70); |
| 233 | nmi_option = NMI_OFF; |
| 234 | get_option(&nmi_option, "nmi"); |
| 235 | if (nmi_option) { |
| 236 | printk(BIOS_INFO, "NMI sources enabled.\n"); |
| 237 | reg8 &= ~(1 << 7); /* Set NMI. */ |
| 238 | } else { |
| 239 | printk(BIOS_INFO, "NMI sources disabled.\n"); |
| 240 | reg8 |= ( 1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */ |
| 241 | } |
| 242 | outb(reg8, 0x70); |
| 243 | |
| 244 | /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */ |
| 245 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 246 | reg16 &= ~(3 << 0); // SMI# rate 1 minute |
| 247 | reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME |
| 248 | #if DEBUG_PERIODIC_SMIS |
| 249 | /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using |
| 250 | * periodic SMIs. |
| 251 | */ |
| 252 | reg16 |= (3 << 0); // Periodic SMI every 8s |
| 253 | #endif |
| 254 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 255 | |
| 256 | // Set the board's GPI routing. |
| 257 | pch_gpi_routing(dev); |
| 258 | |
| 259 | pmbase = pci_read_config16(dev, 0x40) & 0xfffe; |
| 260 | |
| 261 | outl(config->gpe0_en, pmbase + GPE0_EN); |
| 262 | outw(config->alt_gp_smi_en, pmbase + ALT_GP_SMI_EN); |
| 263 | |
| 264 | /* Set up power management block and determine sleep mode */ |
| 265 | reg32 = inl(pmbase + 0x04); // PM1_CNT |
| 266 | reg32 &= ~(7 << 10); // SLP_TYP |
| 267 | reg32 |= (1 << 0); // SCI_EN |
| 268 | outl(reg32, pmbase + 0x04); |
| 269 | |
| 270 | /* Clear magic status bits to prevent unexpected wake */ |
| 271 | reg32 = RCBA32(0x3310); |
| 272 | reg32 |= (1 << 4)|(1 << 5)|(1 << 0); |
| 273 | RCBA32(0x3310) = reg32; |
| 274 | |
| 275 | reg32 = RCBA32(0x3f02); |
| 276 | reg32 &= ~0xf; |
| 277 | RCBA32(0x3f02) = reg32; |
| 278 | } |
| 279 | |
| 280 | static void pch_rtc_init(struct device *dev) |
| 281 | { |
| 282 | u8 reg8; |
| 283 | int rtc_failed; |
| 284 | |
| 285 | reg8 = pci_read_config8(dev, GEN_PMCON_3); |
| 286 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 287 | if (rtc_failed) { |
| 288 | reg8 &= ~RTC_BATTERY_DEAD; |
| 289 | pci_write_config8(dev, GEN_PMCON_3, reg8); |
Duncan Laurie | 800e950 | 2012-06-23 17:06:47 -0700 | [diff] [blame] | 290 | #if CONFIG_ELOG |
| 291 | elog_add_event(ELOG_TYPE_RTC_RESET); |
| 292 | #endif |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 293 | } |
| 294 | printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed); |
| 295 | |
| 296 | rtc_init(rtc_failed); |
| 297 | } |
| 298 | |
Duncan Laurie | 3f6a4d7 | 2012-06-28 13:03:40 -0700 | [diff] [blame] | 299 | /* CougarPoint PCH Power Management init */ |
| 300 | static void cpt_pm_init(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 301 | { |
Duncan Laurie | 3f6a4d7 | 2012-06-28 13:03:40 -0700 | [diff] [blame] | 302 | printk(BIOS_DEBUG, "CougarPoint PM init\n"); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 303 | pci_write_config8(dev, 0xa9, 0x47); |
| 304 | RCBA32_AND_OR(0x2238, ~0UL, (1 << 6)|(1 << 0)); |
| 305 | RCBA32_AND_OR(0x228c, ~0UL, (1 << 0)); |
| 306 | RCBA16_AND_OR(0x1100, ~0UL, (1 << 13)|(1 << 14)); |
| 307 | RCBA16_AND_OR(0x0900, ~0UL, (1 << 14)); |
| 308 | RCBA32(0x2304) = 0xc0388400; |
| 309 | RCBA32_AND_OR(0x2314, ~0UL, (1 << 5)|(1 << 18)); |
| 310 | RCBA32_AND_OR(0x2320, ~0UL, (1 << 15)|(1 << 1)); |
| 311 | RCBA32_AND_OR(0x3314, ~0x1f, 0xf); |
| 312 | RCBA32(0x3318) = 0x050f0000; |
| 313 | RCBA32(0x3324) = 0x04000000; |
| 314 | RCBA32_AND_OR(0x3340, ~0UL, 0xfffff); |
| 315 | RCBA32_AND_OR(0x3344, ~0UL, (1 << 1)); |
| 316 | RCBA32(0x3360) = 0x0001c000; |
| 317 | RCBA32(0x3368) = 0x00061100; |
| 318 | RCBA32(0x3378) = 0x7f8fdfff; |
| 319 | RCBA32(0x337c) = 0x000003fc; |
| 320 | RCBA32(0x3388) = 0x00001000; |
| 321 | RCBA32(0x3390) = 0x0001c000; |
| 322 | RCBA32(0x33a0) = 0x00000800; |
| 323 | RCBA32(0x33b0) = 0x00001000; |
| 324 | RCBA32(0x33c0) = 0x00093900; |
| 325 | RCBA32(0x33cc) = 0x24653002; |
| 326 | RCBA32(0x33d0) = 0x062108fe; |
| 327 | RCBA32_AND_OR(0x33d4, 0xf000f000, 0x00670060); |
| 328 | RCBA32(0x3a28) = 0x01010000; |
| 329 | RCBA32(0x3a2c) = 0x01010404; |
| 330 | RCBA32(0x3a80) = 0x01041041; |
| 331 | RCBA32_AND_OR(0x3a84, ~0x0000ffff, 0x00001001); |
| 332 | RCBA32_AND_OR(0x3a84, ~0UL, (1 << 24)); /* SATA 2/3 disabled */ |
| 333 | RCBA32_AND_OR(0x3a88, ~0UL, (1 << 0)); /* SATA 4/5 disabled */ |
| 334 | RCBA32(0x3a6c) = 0x00000001; |
| 335 | RCBA32_AND_OR(0x2344, 0x00ffff00, 0xff00000c); |
| 336 | RCBA32_AND_OR(0x80c, ~(0xff << 20), 0x11 << 20); |
| 337 | RCBA32(0x33c8) = 0; |
| 338 | RCBA32_AND_OR(0x21b0, ~0UL, 0xf); |
| 339 | } |
| 340 | |
Duncan Laurie | 3f6a4d7 | 2012-06-28 13:03:40 -0700 | [diff] [blame] | 341 | /* PantherPoint PCH Power Management init */ |
| 342 | static void ppt_pm_init(struct device *dev) |
| 343 | { |
| 344 | printk(BIOS_DEBUG, "PantherPoint PM init\n"); |
| 345 | pci_write_config8(dev, 0xa9, 0x47); |
| 346 | RCBA32_AND_OR(0x2238, ~0UL, (1 << 0)); |
| 347 | RCBA32_AND_OR(0x228c, ~0UL, (1 << 0)); |
| 348 | RCBA16_AND_OR(0x1100, ~0UL, (1 << 13)|(1 << 14)); |
| 349 | RCBA16_AND_OR(0x0900, ~0UL, (1 << 14)); |
| 350 | RCBA32(0x2304) = 0xc03b8400; |
| 351 | RCBA32_AND_OR(0x2314, ~0UL, (1 << 5)|(1 << 18)); |
| 352 | RCBA32_AND_OR(0x2320, ~0UL, (1 << 15)|(1 << 1)); |
| 353 | RCBA32_AND_OR(0x3314, ~0x1f, 0xf); |
| 354 | RCBA32(0x3318) = 0x054f0000; |
| 355 | RCBA32(0x3324) = 0x04000000; |
| 356 | RCBA32_AND_OR(0x3340, ~0UL, 0xfffff); |
| 357 | RCBA32_AND_OR(0x3344, ~0UL, (1 << 1)|(1 << 0)); |
| 358 | RCBA32(0x3360) = 0x0001c000; |
| 359 | RCBA32(0x3368) = 0x00061100; |
| 360 | RCBA32(0x3378) = 0x7f8fdfff; |
| 361 | RCBA32(0x337c) = 0x000003fd; |
| 362 | RCBA32(0x3388) = 0x00001000; |
| 363 | RCBA32(0x3390) = 0x0001c000; |
| 364 | RCBA32(0x33a0) = 0x00000800; |
| 365 | RCBA32(0x33b0) = 0x00001000; |
| 366 | RCBA32(0x33c0) = 0x00093900; |
| 367 | RCBA32(0x33cc) = 0x24653002; |
| 368 | RCBA32(0x33d0) = 0x067388fe; |
| 369 | RCBA32_AND_OR(0x33d4, 0xf000f000, 0x00670060); |
| 370 | RCBA32(0x3a28) = 0x01010000; |
| 371 | RCBA32(0x3a2c) = 0x01010404; |
| 372 | RCBA32(0x3a80) = 0x01040000; |
| 373 | RCBA32_AND_OR(0x3a84, ~0x0000ffff, 0x00001001); |
| 374 | RCBA32_AND_OR(0x3a84, ~0UL, (1 << 24)); /* SATA 2/3 disabled */ |
| 375 | RCBA32_AND_OR(0x3a88, ~0UL, (1 << 0)); /* SATA 4/5 disabled */ |
| 376 | RCBA32(0x3a6c) = 0x00000001; |
| 377 | RCBA32_AND_OR(0x2344, 0x00ffff00, 0xff00000c); |
| 378 | RCBA32_AND_OR(0x80c, ~(0xff << 20), 0x11 << 20); |
| 379 | RCBA32_AND_OR(0x33a4, ~0UL, (1 << 0)); |
| 380 | RCBA32(0x33c8) = 0; |
| 381 | RCBA32_AND_OR(0x21b0, ~0UL, 0xf); |
| 382 | } |
| 383 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 384 | static void enable_hpet(void) |
| 385 | { |
| 386 | u32 reg32; |
| 387 | |
| 388 | /* Move HPET to default address 0xfed00000 and enable it */ |
| 389 | reg32 = RCBA32(HPTC); |
| 390 | reg32 |= (1 << 7); // HPET Address Enable |
| 391 | reg32 &= ~(3 << 0); |
| 392 | RCBA32(HPTC) = reg32; |
| 393 | } |
| 394 | |
| 395 | static void enable_clock_gating(device_t dev) |
| 396 | { |
| 397 | u32 reg32; |
| 398 | u16 reg16; |
| 399 | |
| 400 | RCBA32_AND_OR(0x2234, ~0UL, 0xf); |
| 401 | |
| 402 | reg16 = pci_read_config16(dev, GEN_PMCON_1); |
| 403 | reg16 |= (1 << 2) | (1 << 11); |
| 404 | pci_write_config16(dev, GEN_PMCON_1, reg16); |
| 405 | |
| 406 | pch_iobp_update(0xEB007F07, ~0UL, (1 << 31)); |
| 407 | pch_iobp_update(0xEB004000, ~0UL, (1 << 7)); |
| 408 | pch_iobp_update(0xEC007F07, ~0UL, (1 << 31)); |
| 409 | pch_iobp_update(0xEC004000, ~0UL, (1 << 7)); |
| 410 | |
| 411 | reg32 = RCBA32(CG); |
| 412 | reg32 |= (1 << 31); |
| 413 | reg32 |= (1 << 29) | (1 << 28); |
| 414 | reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24); |
| 415 | reg32 |= (1 << 16); |
| 416 | reg32 |= (1 << 17); |
| 417 | reg32 |= (1 << 18); |
| 418 | reg32 |= (1 << 22); |
| 419 | reg32 |= (1 << 23); |
| 420 | reg32 &= ~(1 << 20); |
| 421 | reg32 |= (1 << 19); |
| 422 | reg32 |= (1 << 0); |
| 423 | reg32 |= (0xf << 1); |
| 424 | RCBA32(CG) = reg32; |
| 425 | |
| 426 | RCBA32_OR(0x38c0, 0x7); |
| 427 | RCBA32_OR(0x36d4, 0x6680c004); |
| 428 | RCBA32_OR(0x3564, 0x3); |
| 429 | } |
| 430 | |
| 431 | #if CONFIG_HAVE_SMI_HANDLER |
| 432 | static void pch_lock_smm(struct device *dev) |
| 433 | { |
| 434 | #if TEST_SMM_FLASH_LOCKDOWN |
| 435 | u8 reg8; |
| 436 | #endif |
| 437 | |
Kyösti Mälkki | c3ed886 | 2014-06-19 19:50:51 +0300 | [diff] [blame] | 438 | if (!acpi_is_wakeup_s3()) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 439 | #if ENABLE_ACPI_MODE_IN_COREBOOT |
Duncan Laurie | 95be1d6 | 2012-04-09 12:31:43 -0700 | [diff] [blame] | 440 | printk(BIOS_DEBUG, "Enabling ACPI via APMC:\n"); |
| 441 | outb(0xe1, 0xb2); // Enable ACPI mode |
| 442 | printk(BIOS_DEBUG, "done.\n"); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 443 | #else |
Duncan Laurie | 95be1d6 | 2012-04-09 12:31:43 -0700 | [diff] [blame] | 444 | printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n"); |
| 445 | outb(0x1e, 0xb2); // Disable ACPI mode |
| 446 | printk(BIOS_DEBUG, "done.\n"); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 447 | #endif |
Duncan Laurie | 95be1d6 | 2012-04-09 12:31:43 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 450 | /* Don't allow evil boot loaders, kernels, or |
| 451 | * userspace applications to deceive us: |
| 452 | */ |
| 453 | smm_lock(); |
| 454 | |
| 455 | #if TEST_SMM_FLASH_LOCKDOWN |
| 456 | /* Now try this: */ |
| 457 | printk(BIOS_DEBUG, "Locking BIOS to RO... "); |
| 458 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
| 459 | printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off", |
| 460 | (reg8&1)?"rw":"ro"); |
| 461 | reg8 &= ~(1 << 0); /* clear BIOSWE */ |
| 462 | pci_write_config8(dev, 0xdc, reg8); |
| 463 | reg8 |= (1 << 1); /* set BLE */ |
| 464 | pci_write_config8(dev, 0xdc, reg8); |
| 465 | printk(BIOS_DEBUG, "ok.\n"); |
| 466 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
| 467 | printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off", |
| 468 | (reg8&1)?"rw":"ro"); |
| 469 | |
| 470 | printk(BIOS_DEBUG, "Writing:\n"); |
| 471 | *(volatile u8 *)0xfff00000 = 0x00; |
| 472 | printk(BIOS_DEBUG, "Testing:\n"); |
| 473 | reg8 |= (1 << 0); /* set BIOSWE */ |
| 474 | pci_write_config8(dev, 0xdc, reg8); |
| 475 | |
| 476 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
| 477 | printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off", |
| 478 | (reg8&1)?"rw":"ro"); |
| 479 | printk(BIOS_DEBUG, "Done.\n"); |
| 480 | #endif |
| 481 | } |
| 482 | #endif |
| 483 | |
| 484 | static void pch_disable_smm_only_flashing(struct device *dev) |
| 485 | { |
| 486 | u8 reg8; |
| 487 | |
| 488 | printk(BIOS_SPEW, "Enabling BIOS updates outside of SMM... "); |
| 489 | reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */ |
| 490 | reg8 &= ~(1 << 5); |
| 491 | pci_write_config8(dev, 0xdc, reg8); |
| 492 | } |
| 493 | |
| 494 | static void pch_fixups(struct device *dev) |
| 495 | { |
| 496 | u8 gen_pmcon_2; |
| 497 | |
| 498 | /* Indicate DRAM init done for MRC S3 to know it can resume */ |
| 499 | gen_pmcon_2 = pci_read_config8(dev, GEN_PMCON_2); |
| 500 | gen_pmcon_2 |= (1 << 7); |
| 501 | pci_write_config8(dev, GEN_PMCON_2, gen_pmcon_2); |
| 502 | |
| 503 | /* |
| 504 | * Enable DMI ASPM in the PCH |
| 505 | */ |
| 506 | RCBA32_AND_OR(0x2304, ~(1 << 10), 0); |
| 507 | RCBA32_OR(0x21a4, (1 << 11)|(1 << 10)); |
| 508 | RCBA32_OR(0x21a8, 0x3); |
| 509 | } |
| 510 | |
| 511 | static void pch_decode_init(struct device *dev) |
| 512 | { |
| 513 | config_t *config = dev->chip_info; |
| 514 | |
| 515 | printk(BIOS_DEBUG, "pch_decode_init\n"); |
| 516 | |
| 517 | pci_write_config32(dev, LPC_GEN1_DEC, config->gen1_dec); |
| 518 | pci_write_config32(dev, LPC_GEN2_DEC, config->gen2_dec); |
| 519 | pci_write_config32(dev, LPC_GEN3_DEC, config->gen3_dec); |
| 520 | pci_write_config32(dev, LPC_GEN4_DEC, config->gen4_dec); |
| 521 | } |
| 522 | |
| 523 | static void lpc_init(struct device *dev) |
| 524 | { |
| 525 | printk(BIOS_DEBUG, "pch: lpc_init\n"); |
| 526 | |
| 527 | /* Set the value for PCI command register. */ |
| 528 | pci_write_config16(dev, PCI_COMMAND, 0x000f); |
| 529 | |
| 530 | /* IO APIC initialization. */ |
Paul Menzel | 9c50e6a | 2013-05-03 12:23:39 +0200 | [diff] [blame] | 531 | pch_enable_ioapic(dev); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 532 | |
| 533 | pch_enable_serial_irqs(dev); |
| 534 | |
| 535 | /* Setup the PIRQ. */ |
| 536 | pch_pirq_init(dev); |
| 537 | |
| 538 | /* Setup power options. */ |
| 539 | pch_power_options(dev); |
| 540 | |
| 541 | /* Initialize power management */ |
Duncan Laurie | 3f6a4d7 | 2012-06-28 13:03:40 -0700 | [diff] [blame] | 542 | switch (pch_silicon_type()) { |
| 543 | case PCH_TYPE_CPT: /* CougarPoint */ |
| 544 | cpt_pm_init(dev); |
| 545 | break; |
| 546 | case PCH_TYPE_PPT: /* PantherPoint */ |
| 547 | ppt_pm_init(dev); |
| 548 | break; |
| 549 | default: |
| 550 | printk(BIOS_ERR, "Unknown Chipset: 0x%04x\n", dev->device); |
| 551 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 552 | |
| 553 | /* Set the state of the GPIO lines. */ |
| 554 | //gpio_init(dev); |
| 555 | |
| 556 | /* Initialize the real time clock. */ |
| 557 | pch_rtc_init(dev); |
| 558 | |
| 559 | /* Initialize ISA DMA. */ |
| 560 | isa_dma_init(); |
| 561 | |
| 562 | /* Initialize the High Precision Event Timers, if present. */ |
| 563 | enable_hpet(); |
| 564 | |
| 565 | /* Initialize Clock Gating */ |
| 566 | enable_clock_gating(dev); |
| 567 | |
| 568 | setup_i8259(); |
| 569 | |
| 570 | /* The OS should do this? */ |
| 571 | /* Interrupt 9 should be level triggered (SCI) */ |
| 572 | i8259_configure_irq_trigger(9, 1); |
| 573 | |
| 574 | pch_disable_smm_only_flashing(dev); |
| 575 | |
| 576 | #if CONFIG_HAVE_SMI_HANDLER |
| 577 | pch_lock_smm(dev); |
| 578 | #endif |
| 579 | |
| 580 | pch_fixups(dev); |
| 581 | } |
| 582 | |
| 583 | static void pch_lpc_read_resources(device_t dev) |
| 584 | { |
| 585 | struct resource *res; |
Marc Jones | a0bec17 | 2012-07-13 14:14:34 -0600 | [diff] [blame] | 586 | config_t *config = dev->chip_info; |
| 587 | u8 io_index = 0; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 588 | |
| 589 | /* Get the normal PCI resources of this device. */ |
| 590 | pci_dev_read_resources(dev); |
| 591 | |
| 592 | /* Add an extra subtractive resource for both memory and I/O. */ |
Marc Jones | a0bec17 | 2012-07-13 14:14:34 -0600 | [diff] [blame] | 593 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 594 | res->base = 0; |
| 595 | res->size = 0x1000; |
| 596 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 597 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 598 | |
Marc Jones | a0bec17 | 2012-07-13 14:14:34 -0600 | [diff] [blame] | 599 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
Vladimir Serbinenko | 0650cd0 | 2014-02-05 15:03:50 +0100 | [diff] [blame] | 600 | res->base = 0xff000000; |
| 601 | /* Some systems (e.g. X230) have 12 MiB flash. |
| 602 | SPI controller supports up to 2 x 16 MiB of flash but |
| 603 | address map limits this to 16MiB. */ |
| 604 | res->size = 0x01000000; /* 16 MB for flash */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 605 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 606 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 607 | |
| 608 | res = new_resource(dev, 3); /* IOAPIC */ |
| 609 | res->base = IO_APIC_ADDR; |
| 610 | res->size = 0x00001000; |
| 611 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Marc Jones | a0bec17 | 2012-07-13 14:14:34 -0600 | [diff] [blame] | 612 | |
| 613 | /* Set PCH IO decode ranges if required.*/ |
| 614 | if ((config->gen1_dec & 0xFFFC) > 0x1000) { |
| 615 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 616 | res->base = config->gen1_dec & 0xFFFC; |
| 617 | res->size = (config->gen1_dec >> 16) & 0xFC; |
| 618 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 619 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 620 | } |
| 621 | |
| 622 | if ((config->gen2_dec & 0xFFFC) > 0x1000) { |
| 623 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 624 | res->base = config->gen2_dec & 0xFFFC; |
| 625 | res->size = (config->gen2_dec >> 16) & 0xFC; |
| 626 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 627 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 628 | } |
| 629 | |
| 630 | if ((config->gen3_dec & 0xFFFC) > 0x1000) { |
| 631 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 632 | res->base = config->gen3_dec & 0xFFFC; |
| 633 | res->size = (config->gen3_dec >> 16) & 0xFC; |
| 634 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 635 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 636 | } |
| 637 | |
| 638 | if ((config->gen4_dec & 0xFFFC) > 0x1000) { |
| 639 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 640 | res->base = config->gen4_dec & 0xFFFC; |
| 641 | res->size = (config->gen4_dec >> 16) & 0xFC; |
| 642 | res->flags = IORESOURCE_IO| IORESOURCE_SUBTRACTIVE | |
| 643 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 644 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | static void pch_lpc_enable_resources(device_t dev) |
| 648 | { |
| 649 | pch_decode_init(dev); |
| 650 | return pci_dev_enable_resources(dev); |
| 651 | } |
| 652 | |
| 653 | static void pch_lpc_enable(device_t dev) |
| 654 | { |
| 655 | /* Enable PCH Display Port */ |
| 656 | RCBA16(DISPBDF) = 0x0010; |
| 657 | RCBA32_OR(FD2, PCH_ENABLE_DBDF); |
| 658 | |
| 659 | pch_enable(dev); |
| 660 | } |
| 661 | |
| 662 | static void set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 663 | { |
| 664 | if (!vendor || !device) { |
| 665 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 666 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 667 | } else { |
| 668 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 669 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 670 | } |
| 671 | } |
| 672 | |
Vladimir Serbinenko | 35c0f43 | 2014-09-02 22:25:36 +0200 | [diff] [blame] | 673 | static unsigned long southbridge_fill_ssdt(unsigned long current, const char *oem_table_id) |
| 674 | { |
| 675 | global_nvs_t *gnvs = cbmem_add (CBMEM_ID_ACPI_GNVS, sizeof (*gnvs)); |
| 676 | void *opregion; |
| 677 | |
| 678 | /* Calling northbridge code as gnvs contains opregion address. */ |
| 679 | opregion = igd_make_opregion(); |
| 680 | |
| 681 | if (gnvs) { |
| 682 | int scopelen; |
| 683 | acpi_create_gnvs(gnvs); |
| 684 | /* IGD OpRegion Base Address */ |
| 685 | gnvs->aslb = (u32)opregion; |
| 686 | /* And tell SMI about it */ |
| 687 | smm_setup_structures(gnvs, NULL, NULL); |
| 688 | |
| 689 | /* Add it to SSDT. */ |
| 690 | scopelen = acpigen_write_scope("\\"); |
| 691 | scopelen += acpigen_write_name_dword("NVSA", (u32) gnvs); |
| 692 | acpigen_patch_len(scopelen - 1); |
| 693 | } |
| 694 | |
| 695 | return (unsigned long) (acpigen_get_current()); |
| 696 | } |
| 697 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 698 | static struct pci_operations pci_ops = { |
| 699 | .set_subsystem = set_subsystem, |
| 700 | }; |
| 701 | |
| 702 | static struct device_operations device_ops = { |
| 703 | .read_resources = pch_lpc_read_resources, |
| 704 | .set_resources = pci_dev_set_resources, |
| 705 | .enable_resources = pch_lpc_enable_resources, |
Vladimir Serbinenko | 35c0f43 | 2014-09-02 22:25:36 +0200 | [diff] [blame] | 706 | .write_acpi_tables = acpi_write_hpet, |
| 707 | .acpi_fill_ssdt_generator = southbridge_fill_ssdt, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 708 | .init = lpc_init, |
| 709 | .enable = pch_lpc_enable, |
| 710 | .scan_bus = scan_static_bus, |
| 711 | .ops_pci = &pci_ops, |
| 712 | }; |
| 713 | |
| 714 | |
Kimarie Hoot | e6f459c | 2012-07-14 08:26:08 -0600 | [diff] [blame] | 715 | /* IDs for LPC device of Intel 6 Series Chipset, Intel 7 Series Chipset, and |
| 716 | * Intel C200 Series Chipset |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 717 | */ |
| 718 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 719 | static const unsigned short pci_device_ids[] = { 0x1c46, 0x1c47, 0x1c49, 0x1c4a, |
| 720 | 0x1c4b, 0x1c4c, 0x1c4d, 0x1c4e, |
| 721 | 0x1c4f, 0x1c50, 0x1c52, 0x1c54, |
Kimarie Hoot | e6f459c | 2012-07-14 08:26:08 -0600 | [diff] [blame] | 722 | 0x1e55, 0x1c56, 0x1e57, 0x1c5c, |
| 723 | 0x1e5d, 0x1e5e, 0x1e5f, |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 724 | 0 }; |
| 725 | |
| 726 | static const struct pci_driver pch_lpc __pci_driver = { |
| 727 | .ops = &device_ops, |
| 728 | .vendor = PCI_VENDOR_ID_INTEL, |
| 729 | .devices = pci_device_ids, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 730 | }; |