Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [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 | * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; version 2 of |
| 11 | * the License. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <arch/io.h> |
| 21 | #include <arch/ioapic.h> |
| 22 | #include <cbmem.h> |
| 23 | #include <console/console.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
| 26 | #include <device/pci_ids.h> |
| 27 | #include <device/pci_def.h> |
| 28 | #include <pc80/mc146818rtc.h> |
| 29 | #include <pc80/i8254.h> |
| 30 | #include <pc80/i8259.h> |
| 31 | #include <pc80/isa-dma.h> |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 32 | |
Ben Gardner | fa6014a | 2015-12-08 21:20:25 -0600 | [diff] [blame] | 33 | #include <soc/baytrail.h> |
| 34 | #include <soc/iomap.h> |
| 35 | #include <soc/irq.h> |
| 36 | #include <soc/lpc.h> |
| 37 | #include <soc/nvs.h> |
| 38 | #include <soc/acpi.h> |
| 39 | #include <soc/pci_devs.h> |
| 40 | #include <soc/pmc.h> |
| 41 | #include <soc/ramstage.h> |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 42 | #include "chip.h" |
Vladimir Serbinenko | 7fb149d | 2014-10-08 22:56:27 +0200 | [diff] [blame] | 43 | #include <arch/acpi.h> |
| 44 | #include <arch/acpigen.h> |
| 45 | #include <cpu/cpu.h> |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 46 | |
| 47 | #define ENABLE_ACPI_MODE_IN_COREBOOT 0 |
| 48 | #define TEST_SMM_FLASH_LOCKDOWN 0 |
| 49 | |
| 50 | typedef struct soc_intel_fsp_baytrail_config config_t; |
| 51 | |
| 52 | static inline void |
| 53 | add_mmio_resource(device_t dev, int i, unsigned long addr, unsigned long size) |
| 54 | { |
| 55 | mmio_resource(dev, i, addr >> 10, size >> 10); |
| 56 | } |
| 57 | |
| 58 | static void sc_add_mmio_resources(device_t dev) |
| 59 | { |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 60 | add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE); |
| 61 | add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE); |
| 62 | add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE); |
| 63 | add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE); |
| 64 | add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE); |
| 65 | add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE); |
| 66 | add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE); |
| 67 | add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE); |
| 68 | add_mmio_resource(dev, 0xfff, 0xffffffff - CONFIG_VIRTUAL_ROM_SIZE + 1, |
| 69 | CONFIG_VIRTUAL_ROM_SIZE); /* BIOS ROM */ |
| 70 | add_mmio_resource(dev, 0xfec, IO_APIC_ADDR, 0x00001000); /* IOAPIC */ |
| 71 | } |
| 72 | |
| 73 | /* Default IO range claimed by the LPC device. The upper bound is exclusive. */ |
| 74 | #define LPC_DEFAULT_IO_RANGE_LOWER 0 |
| 75 | #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000 |
| 76 | |
| 77 | static void sc_enable_ioapic(struct device *dev) |
| 78 | { |
| 79 | int i; |
| 80 | u32 reg32; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 81 | volatile u32 *ioapic_index = (u32 *)(IO_APIC_ADDR); |
| 82 | volatile u32 *ioapic_data = (u32 *)(IO_APIC_ADDR + 0x10); |
| 83 | u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0x0f); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Enable ACPI I/O and power management. |
| 87 | * Set SCI IRQ to IRQ9 |
| 88 | */ |
| 89 | write32(ilb_base + ILB_OIC, 0x100); /* AEN */ |
Kevin Paul Herbert | 4104e6c | 2015-02-25 00:36:51 -0800 | [diff] [blame] | 90 | reg32 = read32(ilb_base + ILB_OIC); /* Read back per BWG */ |
| 91 | write32(ilb_base + ILB_ACTL, 0); /* ACTL bit 2:0 SCIS IRQ9 */ |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 92 | |
| 93 | *ioapic_index = 0; |
| 94 | *ioapic_data = (1 << 25); |
| 95 | |
| 96 | /* affirm full set of redirection table entries ("write once") */ |
| 97 | *ioapic_index = 1; |
| 98 | reg32 = *ioapic_data; |
| 99 | *ioapic_index = 1; |
| 100 | *ioapic_data = reg32; |
| 101 | |
| 102 | *ioapic_index = 0; |
| 103 | reg32 = *ioapic_data; |
| 104 | printk(BIOS_DEBUG, "Southbridge APIC ID = %x\n", (reg32 >> 24) & 0x0f); |
| 105 | if (reg32 != (1 << 25)) |
| 106 | die("APIC Error\n"); |
| 107 | |
| 108 | printk(BIOS_SPEW, "Dumping IOAPIC registers\n"); |
| 109 | for (i=0; i<3; i++) { |
| 110 | *ioapic_index = i; |
| 111 | printk(BIOS_SPEW, " reg 0x%04x:", i); |
| 112 | reg32 = *ioapic_data; |
| 113 | printk(BIOS_SPEW, " 0x%08x\n", reg32); |
| 114 | } |
| 115 | |
| 116 | *ioapic_index = 3; /* Select Boot Configuration register. */ |
| 117 | *ioapic_data = 1; /* Use Processor System Bus to deliver interrupts. */ |
| 118 | } |
| 119 | |
| 120 | static void sc_enable_serial_irqs(struct device *dev) |
| 121 | { |
| 122 | #ifdef SETUPSERIQ /* NOT defined. Remove when the TODO is done. */ |
| 123 | /* |
| 124 | * TODO: SERIRQ seems to have a number of problems on baytrail. |
| 125 | * With it enabled, we get some spurious interrupts (ps2) |
| 126 | * in seabios. It also caused IOCHK# NMIs. Remove it |
| 127 | * until we understand how it needs to be configured. |
| 128 | */ |
| 129 | u8 reg8; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 130 | u8 *ibase = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Disable the IOCHK# NMI. Let the NMI handler enable it if it needs. |
| 134 | */ |
| 135 | reg8 = inb(0x61); |
| 136 | reg8 &= 0x0f; /* Higher Nibble must be 0 */ |
| 137 | reg8 |= (1 << 3); /* IOCHK# NMI Disable for now */ |
| 138 | outb(reg8, 0x61); |
| 139 | |
| 140 | write32(ibase + ILB_OIC, read32(ibase + ILB_OIC) | SIRQEN); |
| 141 | write8(ibase + ILB_SERIRQ_CNTL, SCNT_CONTINUOUS_MODE); |
| 142 | |
| 143 | #if !IS_ENABLED(CONFIG_SERIRQ_CONTINUOUS_MODE) |
| 144 | /* |
| 145 | * SoC requires that the System BIOS first set the SERIRQ logic to |
| 146 | * continuous mode operation for at least one frame before switching |
| 147 | * it into quiet mode operation. |
| 148 | */ |
| 149 | outb(0x00, 0xED); /* I/O Delay to get the 1 frame */ |
| 150 | write8(ibase + ILB_SERIRQ_CNTL, SCNT_QUIET_MODE); |
| 151 | #endif |
| 152 | #endif /* DON'T SET UP IRQS */ |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * Write PCI config space IRQ assignments. PCI devices have the INT_LINE |
| 157 | * (0x3C) and INT_PIN (0x3D) registers which report interrupt routing |
| 158 | * information to operating systems and drivers. The INT_PIN register is |
| 159 | * generally read only and reports which interrupt pin A - D it uses. The |
| 160 | * INT_LINE register is configurable and reports which IRQ (generally the |
| 161 | * PIC IRQs 1 - 15) it will use. This needs to take interrupt pin swizzling |
| 162 | * on devices that are downstream on a PCI bridge into account. |
| 163 | * |
| 164 | * This function will loop through all enabled PCI devices and program the |
| 165 | * INT_LINE register with the correct PIC IRQ number for the INT_PIN that it |
| 166 | * uses. It then configures each interrupt in the pic to be level triggered. |
| 167 | */ |
| 168 | static void write_pci_config_irqs(void) |
| 169 | { |
| 170 | device_t irq_dev; |
| 171 | device_t targ_dev; |
| 172 | uint8_t int_line = 0; |
| 173 | uint8_t original_int_pin = 0; |
| 174 | uint8_t new_int_pin = 0; |
| 175 | uint16_t current_bdf = 0; |
| 176 | uint16_t parent_bdf = 0; |
| 177 | uint8_t pirq = 0; |
| 178 | uint8_t device_num = 0; |
| 179 | const struct baytrail_irq_route *ir = &global_baytrail_irq_route; |
| 180 | |
| 181 | if (ir == NULL) { |
| 182 | printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments because" |
| 183 | " 'global_baytrail_irq_route' structure does not exist\n"); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Loop through all enabled devices and program their |
| 189 | * INT_LINE, INT_PIN registers from values taken from |
| 190 | * the Interrupt Route registers in the ILB |
| 191 | */ |
| 192 | printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PCI config space IRQ assignments\n"); |
| 193 | for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 194 | |
| 195 | if ((irq_dev->path.type != DEVICE_PATH_PCI) || |
| 196 | (!irq_dev->enabled)) |
| 197 | continue; |
| 198 | |
| 199 | current_bdf = irq_dev->path.pci.devfn | |
| 200 | irq_dev->bus->secondary << 8; |
| 201 | |
| 202 | /* |
| 203 | * Step 1: Get the INT_PIN and device structure to look for |
| 204 | * in the pirq_data table defined in the mainboard directory. |
| 205 | */ |
| 206 | targ_dev = NULL; |
| 207 | new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev); |
| 208 | if (targ_dev == NULL || new_int_pin < 1) |
| 209 | continue; |
| 210 | |
Martin Roth | ffcd939 | 2015-12-07 16:50:47 -0700 | [diff] [blame] | 211 | /* |
| 212 | * Adjust the INT routing for the PCIe root ports |
| 213 | * See 'Interrupt Generated for INT[A-D] Interrupts' |
| 214 | * Table 241 in Document Number: 538136, Rev. 3.9 |
| 215 | */ |
| 216 | if (PCI_SLOT(targ_dev->path.pci.devfn) == PCIE_DEV && |
| 217 | targ_dev != irq_dev) |
| 218 | new_int_pin = ((new_int_pin - 1 + |
| 219 | PCI_FUNC(targ_dev->path.pci.devfn)) % 4) + 1; |
| 220 | |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 221 | /* Get the original INT_PIN for record keeping */ |
| 222 | original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 223 | |
| 224 | parent_bdf = targ_dev->path.pci.devfn |
| 225 | | targ_dev->bus->secondary << 8; |
| 226 | device_num = PCI_SLOT(parent_bdf); |
| 227 | |
| 228 | if (ir->pcidev[device_num] == 0) { |
| 229 | printk(BIOS_WARNING, |
| 230 | "Warning: PCI Device %d does not have an IRQ entry, skipping it\n", |
| 231 | device_num); |
| 232 | continue; |
| 233 | } |
| 234 | |
| 235 | /* Find the PIRQ that is attached to the INT_PIN this device uses */ |
| 236 | pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4)) & 0xF; |
| 237 | |
| 238 | /* Get the INT_LINE this device/function will use */ |
| 239 | int_line = ir->pic[pirq]; |
| 240 | |
| 241 | if (int_line != PIRQ_PIC_IRQDISABLE) { |
| 242 | /* Set this IRQ to level triggered since it is used by a PCI device */ |
| 243 | i8259_configure_irq_trigger(int_line, IRQ_LEVEL_TRIGGERED); |
| 244 | /* Set the Interrupt Line register in PCI config space */ |
| 245 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 246 | } else { |
| 247 | /* Set the Interrupt line register as "unknown or unused" */ |
| 248 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, |
| 249 | PIRQ_PIC_UNKNOWN_UNUSED); |
| 250 | } |
| 251 | |
| 252 | printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n", |
| 253 | original_int_pin, pin_to_str(original_int_pin)); |
| 254 | if (parent_bdf != current_bdf) |
| 255 | printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n", |
| 256 | new_int_pin, pin_to_str(new_int_pin)); |
| 257 | printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n" |
| 258 | "\tINT_LINE\t: 0x%X (IRQ %d)\n", |
| 259 | 'A' + pirq, int_line, int_line); |
| 260 | } |
| 261 | printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PCI config space IRQ assignments\n"); |
| 262 | } |
| 263 | |
| 264 | static void sc_pirq_init(device_t dev) |
| 265 | { |
| 266 | int i, j; |
| 267 | int pirq; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 268 | u8 *pr_base = (u8 *)(ILB_BASE_ADDRESS + 0x08); |
| 269 | u16 *ir_base = (u16 *)(ILB_BASE_ADDRESS + 0x20); |
| 270 | u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 271 | const struct baytrail_irq_route *ir = &global_baytrail_irq_route; |
| 272 | |
| 273 | /* Set up the PIRQ PIC routing based on static config. */ |
| 274 | printk(BIOS_SPEW, "Start writing IRQ assignments\n" |
| 275 | "PIRQ\tA \tB \tC \tD \tE \tF \tG \tH\n" |
| 276 | "IRQ "); |
| 277 | for (i = 0; i < NUM_PIRQS; i++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 278 | write8(pr_base + i, ir->pic[i]); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 279 | printk(BIOS_SPEW, "\t%d", ir->pic[i]); |
| 280 | } |
| 281 | printk(BIOS_SPEW, "\n\n"); |
| 282 | |
| 283 | /* Set up the per device PIRQ routing based on static config. */ |
| 284 | printk(BIOS_SPEW, "\t\t\tPIRQ[A-H] routed to each INT_PIN[A-D]\n" |
| 285 | "Dev\tINTA (IRQ)\tINTB (IRQ)\tINTC (IRQ)\tINTD (IRQ)\n"); |
| 286 | for (i = 0; i < NUM_OF_PCI_DEVS; i++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 287 | write16(ir_base + i, ir->pcidev[i]); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 288 | |
| 289 | /* If the entry is more than just 0, print it out */ |
| 290 | if(ir->pcidev[i]) { |
| 291 | printk(BIOS_SPEW, " %d: ", i); |
| 292 | for (j = 0; j < 4; j++) { |
| 293 | pirq = (ir->pcidev[i] >> (j * 4)) & 0xF; |
| 294 | printk(BIOS_SPEW, "\t%-4c (%d)", 'A' + pirq, ir->pic[pirq]); |
| 295 | } |
| 296 | printk(BIOS_SPEW, "\n"); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | /* Route SCI to IRQ9 */ |
| 301 | write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9); |
| 302 | printk(BIOS_SPEW, "Finished writing IRQ assignments\n"); |
| 303 | |
| 304 | /* Write IRQ assignments to PCI config space */ |
| 305 | write_pci_config_irqs(); |
| 306 | } |
| 307 | |
| 308 | static inline int io_range_in_default(int base, int size) |
| 309 | { |
| 310 | /* Does it start above the range? */ |
| 311 | if (base >= LPC_DEFAULT_IO_RANGE_UPPER) |
| 312 | return 0; |
| 313 | |
| 314 | /* Is it entirely contained? */ |
| 315 | if (base >= LPC_DEFAULT_IO_RANGE_LOWER && |
| 316 | (base + size) < LPC_DEFAULT_IO_RANGE_UPPER) |
| 317 | return 1; |
| 318 | |
| 319 | /* This will return not in range for partial overlaps. */ |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * Note: this function assumes there is no overlap with the default LPC device's |
| 325 | * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER. |
| 326 | */ |
| 327 | static void sc_add_io_resource(device_t dev, int base, int size, int index) |
| 328 | { |
| 329 | struct resource *res; |
| 330 | |
| 331 | if (io_range_in_default(base, size)) |
| 332 | return; |
| 333 | |
| 334 | res = new_resource(dev, index); |
| 335 | res->base = base; |
| 336 | res->size = size; |
| 337 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | |
| 338 | IORESOURCE_FIXED; |
| 339 | } |
| 340 | |
| 341 | static void sc_add_io_resources(device_t dev) |
| 342 | { |
| 343 | struct resource *res; |
| 344 | u8 io_index = 0; |
| 345 | |
| 346 | /* |
| 347 | * Add the default claimed IO range for the LPC device |
| 348 | * and mark it as subtractive decode. |
| 349 | */ |
| 350 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0)); |
| 351 | res->base = LPC_DEFAULT_IO_RANGE_LOWER; |
| 352 | res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER; |
| 353 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 354 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 355 | |
| 356 | /* GPIO */ |
| 357 | sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE); |
| 358 | |
| 359 | /* ACPI */ |
| 360 | sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE); |
| 361 | } |
| 362 | |
| 363 | static void sc_read_resources(device_t dev) |
| 364 | { |
| 365 | /* Get the normal PCI resources of this device. */ |
| 366 | pci_dev_read_resources(dev); |
| 367 | |
| 368 | /* Add non-standard MMIO resources. */ |
| 369 | sc_add_mmio_resources(dev); |
| 370 | |
| 371 | /* Add IO resources. */ |
| 372 | sc_add_io_resources(dev); |
| 373 | } |
| 374 | |
| 375 | static void enable_hpet(void) |
| 376 | { |
| 377 | } |
| 378 | |
| 379 | static void sc_init(struct device *dev) |
| 380 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 381 | u8 *ibase; |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 382 | |
| 383 | printk(BIOS_DEBUG, "soc: southcluster_init\n"); |
| 384 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 385 | ibase = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 386 | |
| 387 | write8(ibase + ILB_MC, 0); |
| 388 | |
| 389 | /* Set the value for PCI command register. */ |
| 390 | pci_write_config16(dev, PCI_COMMAND, |
| 391 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | |
| 392 | PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); |
| 393 | |
| 394 | /* IO APIC initialization. */ |
| 395 | sc_enable_ioapic(dev); |
| 396 | |
| 397 | sc_enable_serial_irqs(dev); |
| 398 | |
| 399 | /* Setup the PIRQ. */ |
| 400 | sc_pirq_init(dev); |
| 401 | |
| 402 | /* Initialize the High Precision Event Timers, if present. */ |
| 403 | enable_hpet(); |
| 404 | |
| 405 | /* Initialize ISA DMA. */ |
| 406 | isa_dma_init(); |
| 407 | |
| 408 | setup_i8259(); |
| 409 | |
| 410 | setup_i8254(); |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Common code for the south cluster devices. |
| 415 | */ |
| 416 | |
| 417 | /* Set bit in function disable register to hide this device. */ |
| 418 | static void sc_disable_devfn(device_t dev) |
| 419 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 420 | u32 *func_dis = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS); |
| 421 | u32 *func_dis2 = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS2); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 422 | uint32_t fd_mask = 0; |
| 423 | uint32_t fd2_mask = 0; |
| 424 | |
| 425 | #define SET_DIS_MASK(name_) \ |
| 426 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \ |
| 427 | fd_mask |= name_ ## _DIS |
| 428 | #define SET_DIS_MASK2(name_) \ |
| 429 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \ |
| 430 | fd2_mask |= name_ ## _DIS |
| 431 | |
| 432 | switch (dev->path.pci.devfn) { |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 433 | SET_DIS_MASK(LPE); |
| 434 | break; |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 435 | SET_DIS_MASK(TXE); |
| 436 | break; |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 437 | SET_DIS_MASK(PCIE_PORT1); |
| 438 | break; |
| 439 | SET_DIS_MASK(PCIE_PORT2); |
| 440 | break; |
| 441 | SET_DIS_MASK(PCIE_PORT3); |
| 442 | break; |
| 443 | SET_DIS_MASK(PCIE_PORT4); |
| 444 | break; |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 445 | SET_DIS_MASK2(SMBUS); |
| 446 | break; |
| 447 | SET_DIS_MASK(OTG); |
| 448 | /* Disable OTG PHY when OTG is not available. */ |
| 449 | fd2_mask |= OTG_SS_PHY_DIS; |
| 450 | break; |
| 451 | } |
| 452 | |
| 453 | if (fd_mask != 0) { |
| 454 | write32(func_dis, read32(func_dis) | fd_mask); |
| 455 | /* Ensure posted write hits. */ |
| 456 | read32(func_dis); |
| 457 | } |
| 458 | |
| 459 | if (fd2_mask != 0) { |
| 460 | write32(func_dis2, read32(func_dis2) | fd2_mask); |
| 461 | /* Ensure posted write hits. */ |
| 462 | read32(func_dis2); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | static inline void set_d3hot_bits(device_t dev, int offset) |
| 467 | { |
| 468 | uint32_t reg8; |
| 469 | printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset); |
| 470 | reg8 = pci_read_config8(dev, offset + 4); |
| 471 | reg8 |= 0x3; |
| 472 | pci_write_config8(dev, offset + 4, reg8); |
| 473 | } |
| 474 | |
| 475 | /* Parts of the audio subsystem are powered by the HDA device. Therefore, one |
| 476 | * cannot put HDA into D3Hot. Instead perform this workaround to make some of |
| 477 | * the audio paths work for LPE audio. */ |
| 478 | static void hda_work_around(device_t dev) |
| 479 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 480 | u32 *gctl = (u32 *)(TEMP_BASE_ADDRESS + 0x8); |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 481 | |
| 482 | /* Need to set magic register 0x43 to 0xd7 in config space. */ |
| 483 | pci_write_config8(dev, 0x43, 0xd7); |
| 484 | |
| 485 | /* Need to set bit 0 of GCTL to take the device out of reset. However, |
| 486 | * that requires setting up the 64-bit BAR. */ |
| 487 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS); |
| 488 | pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0); |
| 489 | pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY); |
| 490 | write32(gctl, read32(gctl) | 0x1); |
| 491 | pci_write_config8(dev, PCI_COMMAND, 0); |
| 492 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0); |
| 493 | } |
| 494 | |
| 495 | static int place_device_in_d3hot(device_t dev) |
| 496 | { |
| 497 | unsigned offset; |
| 498 | |
| 499 | /* Parts of the HDA block are used for LPE audio as well. |
| 500 | * Therefore assume the HDA will never be put into D3Hot. */ |
| 501 | if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) { |
| 502 | hda_work_around(dev); |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | offset = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 507 | |
| 508 | if (offset != 0) { |
| 509 | set_d3hot_bits(dev, offset); |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | /* For some reason some of the devices don't have the capability |
| 514 | * pointer set correctly. Work around this by hard coding the offset. */ |
| 515 | #define DEV_CASE(name_) \ |
| 516 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC) |
| 517 | |
| 518 | switch (dev->path.pci.devfn) { |
| 519 | DEV_CASE(MIPI): |
| 520 | DEV_CASE(SDIO): |
| 521 | DEV_CASE(EMMC): |
| 522 | DEV_CASE(SD): |
| 523 | DEV_CASE(MMC45): |
| 524 | DEV_CASE(LPE): |
| 525 | DEV_CASE(SIO_DMA1): |
| 526 | DEV_CASE(I2C1): |
| 527 | DEV_CASE(I2C2): |
| 528 | DEV_CASE(I2C3): |
| 529 | DEV_CASE(I2C4): |
| 530 | DEV_CASE(I2C5): |
| 531 | DEV_CASE(I2C6): |
| 532 | DEV_CASE(I2C7): |
| 533 | DEV_CASE(SIO_DMA2): |
| 534 | DEV_CASE(PWM1): |
| 535 | DEV_CASE(PWM2): |
| 536 | DEV_CASE(HSUART1): |
| 537 | DEV_CASE(HSUART2): |
| 538 | DEV_CASE(SPI): |
| 539 | DEV_CASE(OTG): |
| 540 | offset = 0x80; |
| 541 | break; |
| 542 | DEV_CASE(SATA): |
| 543 | DEV_CASE(XHCI): |
| 544 | DEV_CASE(EHCI): |
| 545 | offset = 0x70; |
| 546 | break; |
| 547 | DEV_CASE(HDA): |
| 548 | DEV_CASE(SMBUS): |
| 549 | offset = 0x50; |
| 550 | break; |
| 551 | DEV_CASE(TXE): |
| 552 | /* TXE cannot be placed in D3Hot. */ |
| 553 | return 0; |
| 554 | break; |
| 555 | DEV_CASE(PCIE_PORT1): |
| 556 | DEV_CASE(PCIE_PORT2): |
| 557 | DEV_CASE(PCIE_PORT3): |
| 558 | DEV_CASE(PCIE_PORT4): |
| 559 | offset = 0xa0; |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | if (offset != 0) { |
| 564 | set_d3hot_bits(dev, offset); |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | return -1; |
| 569 | } |
| 570 | |
| 571 | /* Common PCI device function disable. */ |
| 572 | void southcluster_enable_dev(device_t dev) |
| 573 | { |
| 574 | uint32_t reg32; |
| 575 | |
| 576 | if (!dev->enabled) { |
| 577 | int slot = PCI_SLOT(dev->path.pci.devfn); |
| 578 | int func = PCI_FUNC(dev->path.pci.devfn); |
| 579 | printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n", |
| 580 | dev_path(dev), slot, func); |
| 581 | |
| 582 | /* Ensure memory, io, and bus master are all disabled */ |
| 583 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 584 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 585 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 586 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 587 | |
| 588 | /* Place device in D3Hot */ |
| 589 | if (place_device_in_d3hot(dev) < 0) { |
| 590 | printk(BIOS_WARNING, |
| 591 | "Could not place %02x.%01x into D3Hot. " |
| 592 | "Keeping device visible.\n", slot, func); |
| 593 | return; |
| 594 | } |
| 595 | /* Disable this device if possible */ |
| 596 | sc_disable_devfn(dev); |
| 597 | } else { |
| 598 | /* Enable SERR */ |
| 599 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 600 | reg32 |= PCI_COMMAND_SERR; |
| 601 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | static struct device_operations device_ops = { |
| 606 | .read_resources = sc_read_resources, |
| 607 | .set_resources = pci_dev_set_resources, |
Vladimir Serbinenko | 7fb149d | 2014-10-08 22:56:27 +0200 | [diff] [blame] | 608 | .acpi_inject_dsdt_generator = southcluster_inject_dsdt, |
| 609 | .write_acpi_tables = southcluster_write_acpi_tables, |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 610 | .enable_resources = NULL, |
| 611 | .init = sc_init, |
| 612 | .enable = southcluster_enable_dev, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 613 | .scan_bus = scan_lpc_bus, |
Martin Roth | 433659a | 2014-05-12 21:55:00 -0600 | [diff] [blame] | 614 | .ops_pci = &soc_pci_ops, |
| 615 | }; |
| 616 | |
| 617 | static const struct pci_driver southcluster __pci_driver = { |
| 618 | .ops = &device_ops, |
| 619 | .vendor = PCI_VENDOR_ID_INTEL, |
| 620 | .device = LPC_DEVID, |
| 621 | }; |