Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * Copyright (C) 2013 Google Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of 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 |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <arch/io.h> |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame^] | 23 | #include <bootstate.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 24 | #include <cbmem.h> |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 25 | #include <console/console.h> |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame^] | 26 | #include <cpu/x86/smm.h> |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 27 | #include <device/device.h> |
| 28 | #include <device/pci.h> |
| 29 | #include <device/pci_ids.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 30 | #include <pc80/mc146818rtc.h> |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 31 | #include <romstage_handoff.h> |
| 32 | |
| 33 | #include <baytrail/iomap.h> |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 34 | #include <baytrail/irq.h> |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 35 | #include <baytrail/lpc.h> |
| 36 | #include <baytrail/nvs.h> |
| 37 | #include <baytrail/pci_devs.h> |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 38 | #include <baytrail/pmc.h> |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 39 | #include <baytrail/ramstage.h> |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame^] | 40 | #include <baytrail/spi.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 41 | #include "chip.h" |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 42 | |
| 43 | static inline void |
| 44 | add_mmio_resource(device_t dev, int i, unsigned long addr, unsigned long size) |
| 45 | { |
| 46 | mmio_resource(dev, i, addr >> 10, size >> 10); |
| 47 | } |
| 48 | |
| 49 | static void sc_add_mmio_resources(device_t dev) |
| 50 | { |
Duncan Laurie | 7fbe20b | 2013-11-04 17:00:22 -0800 | [diff] [blame] | 51 | add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE); |
| 52 | add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE); |
| 53 | add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE); |
| 54 | add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE); |
| 55 | add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE); |
| 56 | add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE); |
| 57 | add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE); |
| 58 | add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE); |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Default IO range claimed by the LPC device. The upper bound is exclusive. */ |
| 62 | #define LPC_DEFAULT_IO_RANGE_LOWER 0 |
| 63 | #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000 |
| 64 | |
| 65 | static inline int io_range_in_default(int base, int size) |
| 66 | { |
| 67 | /* Does it start above the range? */ |
| 68 | if (base >= LPC_DEFAULT_IO_RANGE_UPPER) |
| 69 | return 0; |
| 70 | |
| 71 | /* Is it entirely contained? */ |
| 72 | if (base >= LPC_DEFAULT_IO_RANGE_LOWER && |
| 73 | (base + size) < LPC_DEFAULT_IO_RANGE_UPPER) |
| 74 | return 1; |
| 75 | |
| 76 | /* This will return not in range for partial overlaps. */ |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Note: this function assumes there is no overlap with the default LPC device's |
| 82 | * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER. |
| 83 | */ |
| 84 | static void sc_add_io_resource(device_t dev, int base, int size, int index) |
| 85 | { |
| 86 | struct resource *res; |
| 87 | |
| 88 | if (io_range_in_default(base, size)) |
| 89 | return; |
| 90 | |
| 91 | res = new_resource(dev, index); |
| 92 | res->base = base; |
| 93 | res->size = size; |
| 94 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 95 | } |
| 96 | |
| 97 | static void sc_add_io_resources(device_t dev) |
| 98 | { |
| 99 | struct resource *res; |
| 100 | |
| 101 | /* Add the default claimed IO range for the LPC device. */ |
| 102 | res = new_resource(dev, 0); |
| 103 | res->base = LPC_DEFAULT_IO_RANGE_LOWER; |
| 104 | res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER; |
| 105 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 106 | |
| 107 | /* GPIO */ |
| 108 | sc_add_io_resource(dev, GPIO_BASE_ADDRESS, 256, GBASE); |
| 109 | |
| 110 | /* ACPI */ |
| 111 | sc_add_io_resource(dev, ACPI_BASE_ADDRESS, 128, ABASE); |
| 112 | } |
| 113 | |
| 114 | static void sc_read_resources(device_t dev) |
| 115 | { |
| 116 | /* Get the normal PCI resources of this device. */ |
| 117 | pci_dev_read_resources(dev); |
| 118 | |
| 119 | /* Add non-standard MMIO resources. */ |
| 120 | sc_add_mmio_resources(dev); |
| 121 | |
| 122 | /* Add IO resources. */ |
| 123 | sc_add_io_resources(dev); |
| 124 | } |
| 125 | |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 126 | static void sc_rtc_init(void) |
| 127 | { |
| 128 | uint32_t gen_pmcon1; |
| 129 | int rtc_fail; |
| 130 | struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 131 | |
| 132 | if (ps != NULL) { |
| 133 | gen_pmcon1 = ps->gen_pmcon1; |
| 134 | } else { |
| 135 | gen_pmcon1 = read32(PMC_BASE_ADDRESS + GEN_PMCON1); |
| 136 | } |
| 137 | |
| 138 | rtc_fail = !!(gen_pmcon1 & RPS); |
| 139 | |
| 140 | if (rtc_fail) { |
| 141 | printk(BIOS_DEBUG, "RTC failure.\n"); |
| 142 | } |
| 143 | |
| 144 | rtc_init(rtc_fail); |
| 145 | } |
| 146 | |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 147 | static void sc_init(device_t dev) |
| 148 | { |
| 149 | int i; |
| 150 | const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08; |
| 151 | const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20; |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 152 | const unsigned long gen_pmcon1 = PMC_BASE_ADDRESS + GEN_PMCON1; |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 153 | const unsigned long actl = ILB_BASE_ADDRESS + ACTL; |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 154 | const struct baytrail_irq_route *ir = &global_baytrail_irq_route; |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 155 | struct soc_intel_baytrail_config *config = dev->chip_info; |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 156 | |
| 157 | /* Set up the PIRQ PIC routing based on static config. */ |
| 158 | for (i = 0; i < NUM_PIRQS; i++) { |
| 159 | write8(pr_base + i*sizeof(ir->pic[i]), ir->pic[i]); |
| 160 | } |
| 161 | /* Set up the per device PIRQ routing base on static config. */ |
| 162 | for (i = 0; i < NUM_IR_DEVS; i++) { |
| 163 | write16(ir_base + i*sizeof(ir->pcidev[i]), ir->pcidev[i]); |
| 164 | } |
Aaron Durbin | 1af3663 | 2013-11-07 10:42:16 -0600 | [diff] [blame] | 165 | |
| 166 | /* Route SCI to IRQ9 */ |
| 167 | write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9); |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 168 | |
| 169 | sc_rtc_init(); |
| 170 | |
| 171 | if (config->disable_slp_x_stretch_sus_fail) { |
| 172 | printk(BIOS_DEBUG, "Disabling slp_x stretching.\n"); |
| 173 | write32(gen_pmcon1, |
| 174 | read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP); |
| 175 | } else { |
| 176 | write32(gen_pmcon1, |
| 177 | read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP); |
| 178 | } |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 179 | } |
| 180 | |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 181 | /* |
| 182 | * Common code for the south cluster devices. |
| 183 | */ |
| 184 | |
| 185 | /* Set bit in function disble register to hide this device. */ |
| 186 | static void sc_disable_devfn(device_t dev) |
| 187 | { |
| 188 | const unsigned long func_dis = PMC_BASE_ADDRESS + FUNC_DIS; |
| 189 | const unsigned long func_dis2 = PMC_BASE_ADDRESS + FUNC_DIS2; |
| 190 | uint32_t mask = 0; |
| 191 | uint32_t mask2 = 0; |
| 192 | |
| 193 | switch (dev->path.pci.devfn) { |
| 194 | case PCI_DEVFN(SDIO_DEV, SDIO_FUNC): |
| 195 | mask |= SDIO_DIS; |
| 196 | break; |
| 197 | case PCI_DEVFN(SD_DEV, SD_FUNC): |
| 198 | mask |= SD_DIS; |
| 199 | break; |
| 200 | case PCI_DEVFN(SATA_DEV, SATA_FUNC): |
| 201 | mask |= SATA_DIS; |
| 202 | break; |
| 203 | case PCI_DEVFN(XHCI_DEV, XHCI_FUNC): |
| 204 | mask |= XHCI_DIS; |
| 205 | /* Disable super speed PHY when XHCI is not available. */ |
| 206 | mask2 |= USH_SS_PHY_DIS; |
| 207 | break; |
| 208 | case PCI_DEVFN(LPE_DEV, LPE_FUNC): |
| 209 | mask |= LPE_DIS; |
| 210 | break; |
| 211 | case PCI_DEVFN(MMC_DEV, MMC_FUNC): |
| 212 | mask |= MMC_DIS; |
| 213 | break; |
| 214 | case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC): |
| 215 | mask |= SIO_DMA1_DIS; |
| 216 | break; |
| 217 | case PCI_DEVFN(I2C1_DEV, I2C1_FUNC): |
| 218 | mask |= I2C1_DIS; |
| 219 | break; |
| 220 | case PCI_DEVFN(I2C2_DEV, I2C2_FUNC): |
| 221 | mask |= I2C1_DIS; |
| 222 | break; |
| 223 | case PCI_DEVFN(I2C3_DEV, I2C3_FUNC): |
| 224 | mask |= I2C3_DIS; |
| 225 | break; |
| 226 | case PCI_DEVFN(I2C4_DEV, I2C4_FUNC): |
| 227 | mask |= I2C4_DIS; |
| 228 | break; |
| 229 | case PCI_DEVFN(I2C5_DEV, I2C5_FUNC): |
| 230 | mask |= I2C5_DIS; |
| 231 | break; |
| 232 | case PCI_DEVFN(I2C6_DEV, I2C6_FUNC): |
| 233 | mask |= I2C6_DIS; |
| 234 | break; |
| 235 | case PCI_DEVFN(I2C7_DEV, I2C7_FUNC): |
| 236 | mask |= I2C7_DIS; |
| 237 | break; |
| 238 | case PCI_DEVFN(TXE_DEV, TXE_FUNC): |
| 239 | mask |= TXE_DIS; |
| 240 | break; |
| 241 | case PCI_DEVFN(HDA_DEV, HDA_FUNC): |
| 242 | mask |= HDA_DIS; |
| 243 | break; |
| 244 | case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC): |
| 245 | mask |= PCIE_PORT1_DIS; |
| 246 | break; |
| 247 | case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC): |
| 248 | mask |= PCIE_PORT2_DIS; |
| 249 | break; |
| 250 | case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC): |
| 251 | mask |= PCIE_PORT3_DIS; |
| 252 | break; |
| 253 | case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC): |
| 254 | mask |= PCIE_PORT4_DIS; |
| 255 | break; |
| 256 | case PCI_DEVFN(EHCI_DEV, EHCI_FUNC): |
| 257 | mask |= EHCI_DIS; |
| 258 | break; |
| 259 | case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC): |
| 260 | mask |= SIO_DMA2_DIS; |
| 261 | break; |
| 262 | case PCI_DEVFN(PWM1_DEV, PWM1_FUNC): |
| 263 | mask |= PWM1_DIS; |
| 264 | break; |
| 265 | case PCI_DEVFN(PWM2_DEV, PWM2_FUNC): |
| 266 | mask |= PWM2_DIS; |
| 267 | break; |
| 268 | case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC): |
| 269 | mask |= HSUART1_DIS; |
| 270 | break; |
| 271 | case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC): |
| 272 | mask |= HSUART2_DIS; |
| 273 | break; |
| 274 | case PCI_DEVFN(SPI_DEV, SPI_FUNC): |
| 275 | mask |= SPI_DIS; |
| 276 | break; |
| 277 | case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC): |
| 278 | mask2 |= SMBUS_DIS; |
| 279 | break; |
| 280 | } |
| 281 | |
| 282 | if (mask != 0) { |
| 283 | write32(func_dis, read32(func_dis) | mask); |
| 284 | /* Ensure posted write hits. */ |
| 285 | read32(func_dis); |
| 286 | } |
| 287 | |
| 288 | if (mask2 != 0) { |
| 289 | write32(func_dis2, read32(func_dis2) | mask2); |
| 290 | /* Ensure posted write hits. */ |
| 291 | read32(func_dis2); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | static inline void set_d3hot_bits(device_t dev, int offset) |
| 296 | { |
| 297 | uint32_t reg8; |
| 298 | printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset); |
| 299 | reg8 = pci_read_config8(dev, offset + 4); |
| 300 | reg8 |= 0x3; |
| 301 | pci_write_config8(dev, offset + 4, reg8); |
| 302 | } |
| 303 | |
Aaron Durbin | 46ab8cd | 2013-10-30 17:07:46 -0500 | [diff] [blame] | 304 | /* Parts of the audio subsystem are powered by the HDA device. Therefore, one |
| 305 | * cannot put HDA into D3Hot. Instead perform this workaround to make some of |
| 306 | * the audio paths work for LPE audio. */ |
| 307 | static void hda_work_around(device_t dev) |
| 308 | { |
| 309 | unsigned long gctl = TEMP_BASE_ADDRESS + 0x8; |
| 310 | |
| 311 | /* Need to set magic register 0x43 to 0xd7 in config space. */ |
| 312 | pci_write_config8(dev, 0x43, 0xd7); |
| 313 | |
| 314 | /* Need to set bit 0 of GCTL to take the device out of reset. However, |
| 315 | * that requires setting up the 64-bit BAR. */ |
| 316 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS); |
| 317 | pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0); |
| 318 | pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY); |
| 319 | write32(gctl, read32(gctl) | 0x1); |
| 320 | pci_write_config8(dev, PCI_COMMAND, 0); |
| 321 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0); |
| 322 | } |
| 323 | |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 324 | static int place_device_in_d3hot(device_t dev) |
| 325 | { |
| 326 | unsigned offset; |
| 327 | |
Aaron Durbin | 46ab8cd | 2013-10-30 17:07:46 -0500 | [diff] [blame] | 328 | /* Parts of the HDA block are used for LPE audio as well. |
| 329 | * Therefore assume the HDA will never be put into D3Hot. */ |
| 330 | if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) { |
| 331 | hda_work_around(dev); |
| 332 | return 0; |
| 333 | } |
| 334 | |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 335 | offset = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 336 | |
| 337 | if (offset != 0) { |
| 338 | set_d3hot_bits(dev, offset); |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | /* For some reason some of the devices don't have the capability |
| 343 | * pointer set correctly. Work around this by hard coding the offset. */ |
| 344 | switch (dev->path.pci.devfn) { |
| 345 | case PCI_DEVFN(SDIO_DEV, SDIO_FUNC): |
| 346 | offset = 0x80; |
| 347 | break; |
| 348 | case PCI_DEVFN(SD_DEV, SD_FUNC): |
| 349 | offset = 0x80; |
| 350 | break; |
| 351 | case PCI_DEVFN(MMC_DEV, MMC_FUNC): |
| 352 | offset = 0x80; |
| 353 | break; |
| 354 | case PCI_DEVFN(LPE_DEV, LPE_FUNC): |
| 355 | offset = 0x80; |
| 356 | break; |
| 357 | case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC): |
| 358 | offset = 0x80; |
| 359 | break; |
| 360 | case PCI_DEVFN(I2C1_DEV, I2C1_FUNC): |
| 361 | offset = 0x80; |
| 362 | break; |
| 363 | case PCI_DEVFN(I2C2_DEV, I2C2_FUNC): |
| 364 | offset = 0x80; |
| 365 | break; |
| 366 | case PCI_DEVFN(I2C3_DEV, I2C3_FUNC): |
| 367 | offset = 0x80; |
| 368 | break; |
| 369 | case PCI_DEVFN(I2C4_DEV, I2C4_FUNC): |
| 370 | offset = 0x80; |
| 371 | break; |
| 372 | case PCI_DEVFN(I2C5_DEV, I2C5_FUNC): |
| 373 | offset = 0x80; |
| 374 | break; |
| 375 | case PCI_DEVFN(I2C6_DEV, I2C6_FUNC): |
| 376 | offset = 0x80; |
| 377 | break; |
| 378 | case PCI_DEVFN(I2C7_DEV, I2C7_FUNC): |
| 379 | offset = 0x80; |
| 380 | break; |
| 381 | case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC): |
| 382 | offset = 0x80; |
| 383 | break; |
| 384 | case PCI_DEVFN(PWM1_DEV, PWM1_FUNC): |
| 385 | offset = 0x80; |
| 386 | break; |
| 387 | case PCI_DEVFN(PWM2_DEV, PWM2_FUNC): |
| 388 | offset = 0x80; |
| 389 | break; |
| 390 | case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC): |
| 391 | offset = 0x80; |
| 392 | break; |
| 393 | case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC): |
| 394 | offset = 0x80; |
| 395 | break; |
| 396 | case PCI_DEVFN(SPI_DEV, SPI_FUNC): |
| 397 | offset = 0x80; |
| 398 | break; |
| 399 | case PCI_DEVFN(SATA_DEV, SATA_FUNC): |
| 400 | offset = 0x70; |
| 401 | break; |
| 402 | case PCI_DEVFN(XHCI_DEV, XHCI_FUNC): |
| 403 | offset = 0x70; |
| 404 | break; |
| 405 | case PCI_DEVFN(EHCI_DEV, EHCI_FUNC): |
| 406 | offset = 0x70; |
| 407 | break; |
| 408 | case PCI_DEVFN(HDA_DEV, HDA_FUNC): |
| 409 | offset = 0x50; |
| 410 | break; |
| 411 | case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC): |
| 412 | offset = 0x50; |
| 413 | break; |
| 414 | case PCI_DEVFN(TXE_DEV, TXE_FUNC): |
Aaron Durbin | 1eae3ee | 2013-10-30 17:08:59 -0500 | [diff] [blame] | 415 | /* TXE cannot be placed in D3Hot. */ |
| 416 | return 0; |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 417 | case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC): |
| 418 | offset = 0xa0; |
| 419 | break; |
| 420 | case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC): |
| 421 | offset = 0xa0; |
| 422 | break; |
| 423 | case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC): |
| 424 | offset = 0xa0; |
| 425 | break; |
| 426 | case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC): |
| 427 | offset = 0xa0; |
| 428 | break; |
| 429 | } |
| 430 | |
| 431 | if (offset != 0) { |
| 432 | set_d3hot_bits(dev, offset); |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | return -1; |
| 437 | } |
| 438 | |
| 439 | /* Common PCI device function disable. */ |
| 440 | void southcluster_enable_dev(device_t dev) |
| 441 | { |
| 442 | uint32_t reg32; |
| 443 | |
| 444 | if (!dev->enabled) { |
| 445 | int slot = PCI_SLOT(dev->path.pci.devfn); |
| 446 | int func = PCI_FUNC(dev->path.pci.devfn); |
| 447 | printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n", |
| 448 | dev_path(dev), slot, func); |
| 449 | |
| 450 | /* Ensure memory, io, and bus master are all disabled */ |
| 451 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 452 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 453 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 454 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 455 | |
| 456 | /* Place device in D3Hot */ |
| 457 | if (place_device_in_d3hot(dev) < 0) { |
| 458 | printk(BIOS_WARNING, |
| 459 | "Could not place %02x.%01x into D3Hot. " |
| 460 | "Keeping device visible.\n", slot, func); |
| 461 | return; |
| 462 | } |
| 463 | /* Disable this device if possible */ |
| 464 | sc_disable_devfn(dev); |
| 465 | } else { |
| 466 | /* Enable SERR */ |
| 467 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 468 | reg32 |= PCI_COMMAND_SERR; |
| 469 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 470 | } |
| 471 | } |
| 472 | |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 473 | static struct device_operations device_ops = { |
| 474 | .read_resources = sc_read_resources, |
| 475 | .set_resources = pci_dev_set_resources, |
| 476 | .enable_resources = NULL, |
Aaron Durbin | 3bde3d7 | 2013-11-04 21:45:52 -0600 | [diff] [blame] | 477 | .init = sc_init, |
Aaron Durbin | d7bc23a | 2013-10-29 16:37:10 -0500 | [diff] [blame] | 478 | .enable = southcluster_enable_dev, |
Duncan Laurie | 5d53554 | 2013-10-31 10:10:20 -0700 | [diff] [blame] | 479 | .scan_bus = scan_static_bus, |
Aaron Durbin | e18d68f | 2013-10-24 00:05:31 -0500 | [diff] [blame] | 480 | .ops_pci = &soc_pci_ops, |
| 481 | }; |
| 482 | |
| 483 | static const struct pci_driver southcluster __pci_driver = { |
| 484 | .ops = &device_ops, |
| 485 | .vendor = PCI_VENDOR_ID_INTEL, |
| 486 | .device = LPC_DEVID, |
| 487 | }; |
Aaron Durbin | 4177db5 | 2014-02-05 14:55:26 -0600 | [diff] [blame^] | 488 | |
| 489 | int __attribute__((weak)) mainboard_get_spi_config(struct spi_config *cfg) |
| 490 | { |
| 491 | return -1; |
| 492 | } |
| 493 | |
| 494 | static void finalize_chipset(void *unused) |
| 495 | { |
| 496 | const unsigned long bcr = SPI_BASE_ADDRESS + BCR; |
| 497 | const unsigned long gcs = RCBA_BASE_ADDRESS + GCS; |
| 498 | const unsigned long gen_pmcon2 = PMC_BASE_ADDRESS + GEN_PMCON2; |
| 499 | const unsigned long etr = PMC_BASE_ADDRESS + ETR; |
| 500 | const unsigned long spi = SPI_BASE_ADDRESS; |
| 501 | struct spi_config cfg; |
| 502 | |
| 503 | /* Set the lock enable on the BIOS control register. */ |
| 504 | write32(bcr, read32(bcr) | BCR_LE); |
| 505 | |
| 506 | /* Set BIOS lock down bit controlling boot block size and swapping. */ |
| 507 | write32(gcs, read32(gcs) | BILD); |
| 508 | |
| 509 | /* Lock sleep stretching policy and set SMI lock. */ |
| 510 | write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK); |
| 511 | |
| 512 | /* Set the CF9 lock. */ |
| 513 | write32(etr, read32(etr) | CF9LOCK); |
| 514 | |
| 515 | if (mainboard_get_spi_config(&cfg) < 0) { |
| 516 | printk(BIOS_DEBUG, "No SPI lockdown configuration.\n"); |
| 517 | } else { |
| 518 | write16(spi + PREOP, cfg.preop); |
| 519 | write16(spi + OPTYPE, cfg.optype); |
| 520 | write32(spi + OPMENU0, cfg.opmenu[0]); |
| 521 | write32(spi + OPMENU1, cfg.opmenu[1]); |
| 522 | write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN); |
| 523 | write32(spi + UVSCC, cfg.uvscc); |
| 524 | write32(spi + LVSCC, cfg.lvscc | VCL); |
| 525 | } |
| 526 | |
| 527 | printk(BIOS_DEBUG, "Finalizing SMM.\n"); |
| 528 | outb(APM_CNT_FINALIZE, APM_CNT); |
| 529 | } |
| 530 | |
| 531 | BOOT_STATE_INIT_ENTRIES(finalize_bscb) = { |
| 532 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, |
| 533 | finalize_chipset, NULL), |
| 534 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 535 | finalize_chipset, NULL), |
| 536 | }; |