Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [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. |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 6 | * Copyright (C) 2015 Intel Corp. |
Frans Hendriks | b55cd54 | 2019-03-06 14:45:12 +0100 | [diff] [blame] | 7 | * Copyright (C) 2018-2019 Eltan B.V. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; version 2 of 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. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 19 | #include <arch/io.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 20 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 21 | #include <device/pci_ops.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 22 | #include <arch/acpi.h> |
Frans Hendriks | ad5e0a8 | 2019-03-18 13:31:56 +0100 | [diff] [blame] | 23 | #include <arch/ioapic.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 24 | #include <bootstate.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 25 | #include "chip.h" |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 26 | #include <console/console.h> |
| 27 | #include <cpu/x86/smm.h> |
| 28 | #include <device/device.h> |
| 29 | #include <device/pci.h> |
| 30 | #include <device/pci_ids.h> |
Frans Hendriks | 2c63017 | 2019-04-02 15:06:29 +0200 | [diff] [blame] | 31 | #include <intelblocks/lpc_lib.h> |
Frans Hendriks | 255f35c | 2018-12-11 15:21:47 +0100 | [diff] [blame] | 32 | #include <pc80/isa-dma.h> |
Frans Hendriks | bd5233e | 2018-12-05 15:24:48 +0100 | [diff] [blame] | 33 | #include <pc80/i8254.h> |
Frans Hendriks | 9348413 | 2018-12-10 12:38:16 +0100 | [diff] [blame] | 34 | #include <pc80/i8259.h> |
Lee Leahy | 2bc9cee | 2015-06-30 15:25:44 -0700 | [diff] [blame] | 35 | #include <soc/acpi.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 36 | #include <soc/iomap.h> |
| 37 | #include <soc/irq.h> |
| 38 | #include <soc/lpc.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 39 | #include <soc/pci_devs.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 40 | #include <soc/pm.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 41 | #include <soc/ramstage.h> |
| 42 | #include <soc/spi.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 43 | #include <spi-generic.h> |
| 44 | #include <stdint.h> |
Hannah Williams | 3fa80a9 | 2017-03-22 16:33:36 -0700 | [diff] [blame] | 45 | |
Frans Hendriks | 2c63017 | 2019-04-02 15:06:29 +0200 | [diff] [blame] | 46 | static void sc_set_serial_irqs_mode(struct device *dev, enum serirq_mode mode) |
Hannah Williams | 3fa80a9 | 2017-03-22 16:33:36 -0700 | [diff] [blame] | 47 | { |
Frans Hendriks | 2c63017 | 2019-04-02 15:06:29 +0200 | [diff] [blame] | 48 | u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF); |
| 49 | |
| 50 | switch (mode) { |
| 51 | case SERIRQ_CONTINUOUS: |
| 52 | break; |
| 53 | case SERIRQ_OFF: |
| 54 | write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) & |
| 55 | ~SIRQEN); |
| 56 | break; |
| 57 | case SERIRQ_QUIET: |
| 58 | default: |
| 59 | write8(ilb_base + SCNT, read8(ilb_base + SCNT) & ~SCNT_MODE); |
| 60 | break; |
| 61 | } |
Hannah Williams | 3fa80a9 | 2017-03-22 16:33:36 -0700 | [diff] [blame] | 62 | } |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 63 | |
| 64 | static inline void |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 65 | add_mmio_resource(struct device *dev, int i, unsigned long addr, |
| 66 | unsigned long size) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 67 | { |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 68 | printk(BIOS_SPEW, "%s/%s (%s, 0x%016lx, 0x%016lx)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 69 | __FILE__, __func__, dev_name(dev), addr, size); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 70 | mmio_resource(dev, i, addr >> 10, size >> 10); |
| 71 | } |
| 72 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 73 | static void sc_add_mmio_resources(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 74 | { |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 75 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 76 | __FILE__, __func__, dev_name(dev)); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 77 | add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE); |
| 78 | add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE); |
| 79 | add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE); |
| 80 | add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE); |
| 81 | add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE); |
| 82 | add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE); |
| 83 | add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE); |
| 84 | add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE); |
Frans Hendriks | ad5e0a8 | 2019-03-18 13:31:56 +0100 | [diff] [blame] | 85 | add_mmio_resource(dev, 0xfff, |
| 86 | 0xffffffff - (CONFIG_COREBOOT_ROMSIZE_KB*KiB) + 1, |
| 87 | (CONFIG_COREBOOT_ROMSIZE_KB*KiB)); /* BIOS ROM */ |
| 88 | add_mmio_resource(dev, 0xfec, IO_APIC_ADDR, 0x00001000); /* IOAPIC */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* Default IO range claimed by the LPC device. The upper bound is exclusive. */ |
| 92 | #define LPC_DEFAULT_IO_RANGE_LOWER 0 |
| 93 | #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000 |
| 94 | |
Frans Hendriks | 2c63017 | 2019-04-02 15:06:29 +0200 | [diff] [blame] | 95 | static void sc_enable_serial_irqs(struct device *dev) |
| 96 | { |
| 97 | u8 *ilb_base = (u8 *)(pci_read_config32(dev, IBASE) & ~0xF); |
| 98 | |
| 99 | printk(BIOS_SPEW, "Enable serial irq\n"); |
| 100 | write32(ilb_base + ILB_OIC, read32(ilb_base + ILB_OIC) | SIRQEN); |
| 101 | write8(ilb_base + SCNT, read8(ilb_base + SCNT) | SCNT_MODE); |
| 102 | } |
| 103 | |
Frans Hendriks | 9348413 | 2018-12-10 12:38:16 +0100 | [diff] [blame] | 104 | /* |
| 105 | * Write PCI config space IRQ assignments. PCI devices have the INT_LINE |
| 106 | * (0x3C) and INT_PIN (0x3D) registers which report interrupt routing |
| 107 | * information to operating systems and drivers. The INT_PIN register is |
| 108 | * generally read only and reports which interrupt pin A - D it uses. The |
| 109 | * INT_LINE register is configurable and reports which IRQ (generally the |
| 110 | * PIC IRQs 1 - 15) it will use. This needs to take interrupt pin swizzling |
| 111 | * on devices that are downstream on a PCI bridge into account. |
| 112 | * |
| 113 | * This function will loop through all enabled PCI devices and program the |
| 114 | * INT_LINE register with the correct PIC IRQ number for the INT_PIN that it |
| 115 | * uses. It then configures each interrupt in the pic to be level triggered. |
| 116 | */ |
| 117 | static void write_pci_config_irqs(void) |
| 118 | { |
| 119 | struct device *irq_dev; |
| 120 | struct device *targ_dev; |
| 121 | uint8_t int_line = 0; |
| 122 | uint8_t original_int_pin = 0; |
| 123 | uint8_t new_int_pin = 0; |
| 124 | uint16_t current_bdf = 0; |
| 125 | uint16_t parent_bdf = 0; |
| 126 | uint8_t pirq = 0; |
| 127 | uint8_t device_num = 0; |
| 128 | const struct soc_irq_route *ir = &global_soc_irq_route; |
| 129 | |
| 130 | if (ir == NULL) { |
| 131 | printk(BIOS_WARNING, "Warning: Can't write PCI IRQ assignments" |
| 132 | " because 'global_braswell_irq_route' structure does" |
| 133 | " not exist\n"); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Loop through all enabled devices and program their |
| 139 | * INT_LINE, INT_PIN registers from values taken from |
| 140 | * the Interrupt Route registers in the ILB |
| 141 | */ |
| 142 | printk(BIOS_DEBUG, "PCI_CFG IRQ: Write PIRQ assignments\n"); |
| 143 | for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 144 | |
| 145 | if ((irq_dev->path.type != DEVICE_PATH_PCI) || |
| 146 | (!irq_dev->enabled)) |
| 147 | continue; |
| 148 | |
| 149 | current_bdf = irq_dev->path.pci.devfn | |
| 150 | irq_dev->bus->secondary << 8; |
| 151 | |
| 152 | /* |
| 153 | * Step 1: Get the INT_PIN and device structure to look for |
| 154 | * in the pirq_data table defined in the mainboard directory. |
| 155 | */ |
| 156 | targ_dev = NULL; |
| 157 | new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev); |
| 158 | if (targ_dev == NULL || new_int_pin < 1) |
| 159 | continue; |
| 160 | |
| 161 | /* Get the original INT_PIN for record keeping */ |
| 162 | original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 163 | |
| 164 | parent_bdf = targ_dev->path.pci.devfn |
| 165 | | targ_dev->bus->secondary << 8; |
| 166 | device_num = PCI_SLOT(parent_bdf); |
| 167 | |
| 168 | if (ir->pcidev[device_num] == 0) { |
| 169 | printk(BIOS_WARNING, |
| 170 | "Warning: PCI Device %d does not have an IRQ " |
| 171 | "entry, skipping it\n", device_num); |
| 172 | continue; |
| 173 | } |
| 174 | |
| 175 | /* Find the PIRQ that is attached to the INT_PIN */ |
| 176 | pirq = (ir->pcidev[device_num] >> ((new_int_pin - 1) * 4)) |
| 177 | & 0x7; |
| 178 | |
| 179 | /* Get the INT_LINE this device/function will use */ |
| 180 | int_line = ir->pic[pirq]; |
| 181 | |
| 182 | if (int_line != PIRQ_PIC_IRQDISABLE) { |
| 183 | /* Set this IRQ to level triggered */ |
| 184 | i8259_configure_irq_trigger(int_line, |
| 185 | IRQ_LEVEL_TRIGGERED); |
| 186 | /* Set the Interrupt Line register */ |
| 187 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, |
| 188 | int_line); |
| 189 | } else { |
| 190 | /* |
| 191 | * Set the Interrupt line register as 'unknown' or |
| 192 | * 'unused' |
| 193 | */ |
| 194 | pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, |
| 195 | PIRQ_PIC_UNKNOWN_UNUSED); |
| 196 | } |
| 197 | |
| 198 | printk(BIOS_SPEW, "\tINT_PIN\t\t: %d (%s)\n", |
| 199 | original_int_pin, pin_to_str(original_int_pin)); |
| 200 | if (parent_bdf != current_bdf) |
| 201 | printk(BIOS_SPEW, "\tSwizzled to\t: %d (%s)\n", |
| 202 | new_int_pin, pin_to_str(new_int_pin)); |
| 203 | printk(BIOS_SPEW, "\tPIRQ\t\t: %c\n" |
| 204 | "\tINT_LINE\t: 0x%X (IRQ %d)\n", |
| 205 | 'A' + pirq, int_line, int_line); |
| 206 | } |
| 207 | printk(BIOS_DEBUG, "PCI_CFG IRQ: Finished writing PIRQ assignments\n"); |
| 208 | } |
| 209 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 210 | static inline int io_range_in_default(int base, int size) |
| 211 | { |
| 212 | /* Does it start above the range? */ |
| 213 | if (base >= LPC_DEFAULT_IO_RANGE_UPPER) |
| 214 | return 0; |
| 215 | |
| 216 | /* Is it entirely contained? */ |
| 217 | if (base >= LPC_DEFAULT_IO_RANGE_LOWER && |
| 218 | (base + size) < LPC_DEFAULT_IO_RANGE_UPPER) |
| 219 | return 1; |
| 220 | |
| 221 | /* This will return not in range for partial overlaps. */ |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Note: this function assumes there is no overlap with the default LPC device's |
| 227 | * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER. |
| 228 | */ |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 229 | static void sc_add_io_resource(struct device *dev, int base, int size, |
| 230 | int index) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 231 | { |
| 232 | struct resource *res; |
| 233 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 234 | printk(BIOS_SPEW, "%s/%s (%s, 0x%08x, 0x%08x, 0x%08x)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 235 | __FILE__, __func__, dev_name(dev), base, size, index); |
| 236 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 237 | if (io_range_in_default(base, size)) |
| 238 | return; |
| 239 | |
| 240 | res = new_resource(dev, index); |
| 241 | res->base = base; |
| 242 | res->size = size; |
| 243 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 244 | } |
| 245 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 246 | static void sc_add_io_resources(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 247 | { |
| 248 | struct resource *res; |
| 249 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 250 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 251 | __FILE__, __func__, dev_name(dev)); |
| 252 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 253 | /* Add the default claimed IO range for the LPC device. */ |
| 254 | res = new_resource(dev, 0); |
| 255 | res->base = LPC_DEFAULT_IO_RANGE_LOWER; |
| 256 | res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER; |
| 257 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 258 | |
| 259 | /* GPIO */ |
Frans Hendriks | 4b2c12f | 2018-11-22 07:52:38 +0100 | [diff] [blame] | 260 | sc_add_io_resource(dev, GPIO_BASE_ADDRESS, GPIO_BASE_SIZE, GBASE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 261 | |
| 262 | /* ACPI */ |
Frans Hendriks | 4b2c12f | 2018-11-22 07:52:38 +0100 | [diff] [blame] | 263 | sc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, ABASE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 266 | static void sc_read_resources(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 267 | { |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 268 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 269 | __FILE__, __func__, dev_name(dev)); |
| 270 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 271 | /* Get the normal PCI resources of this device. */ |
| 272 | pci_dev_read_resources(dev); |
| 273 | |
| 274 | /* Add non-standard MMIO resources. */ |
| 275 | sc_add_mmio_resources(dev); |
| 276 | |
| 277 | /* Add IO resources. */ |
| 278 | sc_add_io_resources(dev); |
| 279 | } |
| 280 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 281 | static void sc_init(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 282 | { |
| 283 | int i; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 284 | const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08; |
| 285 | const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20; |
Frans Hendriks | b55cd54 | 2019-03-06 14:45:12 +0100 | [diff] [blame] | 286 | const unsigned long ilb_base = ILB_BASE_ADDRESS; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 287 | void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 288 | const struct soc_irq_route *ir = &global_soc_irq_route; |
| 289 | struct soc_intel_braswell_config *config = dev->chip_info; |
| 290 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 291 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 292 | __FILE__, __func__, dev_name(dev)); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 293 | |
Frans Hendriks | b55cd54 | 2019-03-06 14:45:12 +0100 | [diff] [blame] | 294 | /* Set the value for PCI command register. */ |
| 295 | pci_write_config16(dev, PCI_COMMAND, |
| 296 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY | |
| 297 | PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); |
| 298 | |
| 299 | /* Use IRQ9 for SCI Interrupt */ |
| 300 | write32((void *)(ilb_base + ACTL), 0); |
| 301 | |
Frans Hendriks | 255f35c | 2018-12-11 15:21:47 +0100 | [diff] [blame] | 302 | isa_dma_init(); |
| 303 | |
Frans Hendriks | 2c63017 | 2019-04-02 15:06:29 +0200 | [diff] [blame] | 304 | sc_enable_serial_irqs(dev); |
| 305 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 306 | /* Set up the PIRQ PIC routing based on static config. */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 307 | for (i = 0; i < NUM_PIRQS; i++) |
| 308 | write8((void *)(pr_base + i*sizeof(ir->pic[i])), |
| 309 | ir->pic[i]); |
| 310 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 311 | /* Set up the per device PIRQ routing base on static config. */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 312 | for (i = 0; i < NUM_IR_DEVS; i++) |
| 313 | write16((void *)(ir_base + i*sizeof(ir->pcidev[i])), |
| 314 | ir->pcidev[i]); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 315 | |
Frans Hendriks | 9348413 | 2018-12-10 12:38:16 +0100 | [diff] [blame] | 316 | /* Interrupt 9 should be level triggered (SCI) */ |
| 317 | i8259_configure_irq_trigger(9, 1); |
| 318 | |
| 319 | for (i = 0; i < NUM_PIRQS; i++) { |
| 320 | if (ir->pic[i]) |
| 321 | i8259_configure_irq_trigger(ir->pic[i], 1); |
| 322 | } |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 323 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 324 | if (config->disable_slp_x_stretch_sus_fail) { |
| 325 | printk(BIOS_DEBUG, "Disabling slp_x stretching.\n"); |
| 326 | write32(gen_pmcon1, |
| 327 | read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP); |
| 328 | } else { |
| 329 | write32(gen_pmcon1, |
| 330 | read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP); |
| 331 | } |
| 332 | |
Frans Hendriks | 9348413 | 2018-12-10 12:38:16 +0100 | [diff] [blame] | 333 | /* Write IRQ assignments to PCI config space */ |
| 334 | write_pci_config_irqs(); |
| 335 | |
| 336 | /* Initialize i8259 pic */ |
| 337 | setup_i8259(); |
| 338 | |
Frans Hendriks | bd5233e | 2018-12-05 15:24:48 +0100 | [diff] [blame] | 339 | /* Initialize i8254 timers */ |
| 340 | setup_i8254(); |
Frans Hendriks | 2c63017 | 2019-04-02 15:06:29 +0200 | [diff] [blame] | 341 | |
| 342 | sc_set_serial_irqs_mode(dev, config->serirq_mode); |
| 343 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Common code for the south cluster devices. |
| 348 | */ |
| 349 | |
Frans Hendriks | e6bf51f | 2019-05-01 10:48:31 +0200 | [diff] [blame] | 350 | /* Set bit in function disable register to hide this device. */ |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 351 | static void sc_disable_devfn(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 352 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 353 | void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS); |
| 354 | void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 355 | uint32_t mask = 0; |
| 356 | uint32_t mask2 = 0; |
| 357 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 358 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 359 | __FILE__, __func__, dev_name(dev)); |
| 360 | |
| 361 | #define SET_DIS_MASK(name_) \ |
| 362 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \ |
| 363 | mask |= name_ ## _DIS |
| 364 | #define SET_DIS_MASK2(name_) \ |
| 365 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \ |
| 366 | mask2 |= name_ ## _DIS |
| 367 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 368 | switch (dev->path.pci.devfn) { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 369 | SET_DIS_MASK(SDIO); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 370 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 371 | SET_DIS_MASK(SD); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 372 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 373 | SET_DIS_MASK(SATA); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 374 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 375 | SET_DIS_MASK(XHCI); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 376 | /* Disable super speed PHY when XHCI is not available. */ |
| 377 | mask2 |= USH_SS_PHY_DIS; |
| 378 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 379 | SET_DIS_MASK(LPE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 380 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 381 | SET_DIS_MASK(MMC); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 382 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 383 | SET_DIS_MASK(SIO_DMA1); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 384 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 385 | SET_DIS_MASK(I2C1); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 386 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 387 | SET_DIS_MASK(I2C2); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 388 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 389 | SET_DIS_MASK(I2C3); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 390 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 391 | SET_DIS_MASK(I2C4); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 392 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 393 | SET_DIS_MASK(I2C5); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 394 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 395 | SET_DIS_MASK(I2C6); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 396 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 397 | SET_DIS_MASK(I2C7); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 398 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 399 | SET_DIS_MASK(TXE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 400 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 401 | SET_DIS_MASK(HDA); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 402 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 403 | SET_DIS_MASK(PCIE_PORT1); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 404 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 405 | SET_DIS_MASK(PCIE_PORT2); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 406 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 407 | SET_DIS_MASK(PCIE_PORT3); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 408 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 409 | SET_DIS_MASK(PCIE_PORT4); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 410 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 411 | SET_DIS_MASK(SIO_DMA2); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 412 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 413 | SET_DIS_MASK(PWM1); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 414 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 415 | SET_DIS_MASK(PWM2); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 416 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 417 | SET_DIS_MASK(HSUART1); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 418 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 419 | SET_DIS_MASK(HSUART2); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 420 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 421 | SET_DIS_MASK(SPI); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 422 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 423 | SET_DIS_MASK2(SMBUS); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 424 | break; |
| 425 | } |
| 426 | |
| 427 | if (mask != 0) { |
| 428 | write32(func_dis, read32(func_dis) | mask); |
| 429 | /* Ensure posted write hits. */ |
| 430 | read32(func_dis); |
| 431 | } |
| 432 | |
| 433 | if (mask2 != 0) { |
| 434 | write32(func_dis2, read32(func_dis2) | mask2); |
| 435 | /* Ensure posted write hits. */ |
| 436 | read32(func_dis2); |
| 437 | } |
| 438 | } |
| 439 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 440 | static inline void set_d3hot_bits(struct device *dev, int offset) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 441 | { |
| 442 | uint32_t reg8; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 443 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 444 | printk(BIOS_SPEW, "%s/%s (%s, 0x%08x)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 445 | __FILE__, __func__, dev_name(dev), offset); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 446 | printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset); |
| 447 | reg8 = pci_read_config8(dev, offset + 4); |
| 448 | reg8 |= 0x3; |
| 449 | pci_write_config8(dev, offset + 4, reg8); |
| 450 | } |
| 451 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 452 | /* |
| 453 | * Parts of the audio subsystem are powered by the HDA device. Therefore, one |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 454 | * cannot put HDA into D3Hot. Instead perform this workaround to make some of |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 455 | * the audio paths work for LPE audio. |
| 456 | */ |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 457 | static void hda_work_around(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 458 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 459 | void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8); |
| 460 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 461 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 462 | __FILE__, __func__, dev_name(dev)); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 463 | |
| 464 | /* Need to set magic register 0x43 to 0xd7 in config space. */ |
| 465 | pci_write_config8(dev, 0x43, 0xd7); |
| 466 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 467 | /* |
| 468 | * Need to set bit 0 of GCTL to take the device out of reset. However, |
| 469 | * that requires setting up the 64-bit BAR. |
| 470 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 471 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS); |
| 472 | pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0); |
| 473 | pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY); |
| 474 | write32(gctl, read32(gctl) | 0x1); |
| 475 | pci_write_config8(dev, PCI_COMMAND, 0); |
| 476 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0); |
| 477 | } |
| 478 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 479 | static int place_device_in_d3hot(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 480 | { |
Lee Leahy | 1072e7d | 2017-03-16 17:35:32 -0700 | [diff] [blame] | 481 | unsigned int offset; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 482 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 483 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 484 | __FILE__, __func__, dev_name(dev)); |
| 485 | |
| 486 | /* |
| 487 | * Parts of the HDA block are used for LPE audio as well. |
| 488 | * Therefore assume the HDA will never be put into D3Hot. |
| 489 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 490 | if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) { |
| 491 | hda_work_around(dev); |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | offset = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 496 | |
| 497 | if (offset != 0) { |
| 498 | set_d3hot_bits(dev, offset); |
| 499 | return 0; |
| 500 | } |
| 501 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 502 | /* |
| 503 | * For some reason some of the devices don't have the capability |
| 504 | * pointer set correctly. Work around this by hard coding the offset. |
| 505 | */ |
| 506 | #define DEV_CASE(name_) \ |
| 507 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC) |
| 508 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 509 | switch (dev->path.pci.devfn) { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 510 | DEV_CASE(SDIO) : |
| 511 | DEV_CASE(SD) : |
| 512 | DEV_CASE(MMC) : |
| 513 | DEV_CASE(LPE) : |
| 514 | DEV_CASE(SIO_DMA1) : |
| 515 | DEV_CASE(I2C1) : |
| 516 | DEV_CASE(I2C2) : |
| 517 | DEV_CASE(I2C3) : |
| 518 | DEV_CASE(I2C4) : |
| 519 | DEV_CASE(I2C5) : |
| 520 | DEV_CASE(I2C6) : |
| 521 | DEV_CASE(I2C7) : |
| 522 | DEV_CASE(SIO_DMA2) : |
| 523 | DEV_CASE(PWM1) : |
| 524 | DEV_CASE(PWM2) : |
| 525 | DEV_CASE(HSUART1) : |
| 526 | DEV_CASE(HSUART2) : |
| 527 | DEV_CASE(SPI) : |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 528 | offset = 0x80; |
| 529 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 530 | DEV_CASE(SATA) : |
| 531 | DEV_CASE(XHCI) : |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 532 | offset = 0x70; |
| 533 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 534 | DEV_CASE(HDA) : |
| 535 | DEV_CASE(SMBUS) : |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 536 | offset = 0x50; |
| 537 | break; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 538 | DEV_CASE(TXE) : |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 539 | /* TXE cannot be placed in D3Hot. */ |
| 540 | return 0; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 541 | DEV_CASE(PCIE_PORT1) : |
| 542 | DEV_CASE(PCIE_PORT2) : |
| 543 | DEV_CASE(PCIE_PORT3) : |
| 544 | DEV_CASE(PCIE_PORT4) : |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 545 | offset = 0xa0; |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | if (offset != 0) { |
| 550 | set_d3hot_bits(dev, offset); |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | return -1; |
| 555 | } |
| 556 | |
| 557 | /* Common PCI device function disable. */ |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 558 | void southcluster_enable_dev(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 559 | { |
| 560 | uint32_t reg32; |
| 561 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 562 | printk(BIOS_SPEW, "%s/%s (%s)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 563 | __FILE__, __func__, dev_name(dev)); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 564 | if (!dev->enabled) { |
| 565 | int slot = PCI_SLOT(dev->path.pci.devfn); |
| 566 | int func = PCI_FUNC(dev->path.pci.devfn); |
| 567 | printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n", |
| 568 | dev_path(dev), slot, func); |
| 569 | |
| 570 | /* Ensure memory, io, and bus master are all disabled */ |
| 571 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 572 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 573 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 574 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 575 | |
| 576 | /* Place device in D3Hot */ |
| 577 | if (place_device_in_d3hot(dev) < 0) { |
| 578 | printk(BIOS_WARNING, |
| 579 | "Could not place %02x.%01x into D3Hot. " |
| 580 | "Keeping device visible.\n", slot, func); |
| 581 | return; |
| 582 | } |
| 583 | /* Disable this device if possible */ |
| 584 | sc_disable_devfn(dev); |
| 585 | } else { |
| 586 | /* Enable SERR */ |
| 587 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 588 | reg32 |= PCI_COMMAND_SERR; |
| 589 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | static struct device_operations device_ops = { |
| 594 | .read_resources = sc_read_resources, |
| 595 | .set_resources = pci_dev_set_resources, |
| 596 | .enable_resources = NULL, |
Lee Leahy | 2bc9cee | 2015-06-30 15:25:44 -0700 | [diff] [blame] | 597 | .acpi_inject_dsdt_generator = southcluster_inject_dsdt, |
| 598 | .write_acpi_tables = southcluster_write_acpi_tables, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 599 | .init = sc_init, |
| 600 | .enable = southcluster_enable_dev, |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 601 | .scan_bus = scan_lpc_bus, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 602 | .ops_pci = &soc_pci_ops, |
| 603 | }; |
| 604 | |
| 605 | static const struct pci_driver southcluster __pci_driver = { |
| 606 | .ops = &device_ops, |
| 607 | .vendor = PCI_VENDOR_ID_INTEL, |
| 608 | .device = LPC_DEVID, |
| 609 | }; |
| 610 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 611 | int __weak mainboard_get_spi_config(struct spi_config *cfg) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 612 | { |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 613 | printk(BIOS_SPEW, "%s/%s (0x%p)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 614 | __FILE__, __func__, (void *)cfg); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 615 | return -1; |
| 616 | } |
| 617 | |
| 618 | static void finalize_chipset(void *unused) |
| 619 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 620 | void *bcr = (void *)(SPI_BASE_ADDRESS + BCR); |
| 621 | void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS); |
| 622 | void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2); |
| 623 | void *etr = (void *)(PMC_BASE_ADDRESS + ETR); |
| 624 | uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 625 | struct spi_config cfg; |
| 626 | |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 627 | printk(BIOS_SPEW, "%s/%s (0x%p)\n", |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 628 | __FILE__, __func__, unused); |
| 629 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 630 | /* Set the lock enable on the BIOS control register. */ |
| 631 | write32(bcr, read32(bcr) | BCR_LE); |
| 632 | |
| 633 | /* Set BIOS lock down bit controlling boot block size and swapping. */ |
| 634 | write32(gcs, read32(gcs) | BILD); |
| 635 | |
| 636 | /* Lock sleep stretching policy and set SMI lock. */ |
| 637 | write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK); |
| 638 | |
| 639 | /* Set the CF9 lock. */ |
| 640 | write32(etr, read32(etr) | CF9LOCK); |
| 641 | |
| 642 | if (mainboard_get_spi_config(&cfg) < 0) { |
| 643 | printk(BIOS_DEBUG, "No SPI lockdown configuration.\n"); |
| 644 | } else { |
| 645 | write16(spi + PREOP, cfg.preop); |
| 646 | write16(spi + OPTYPE, cfg.optype); |
| 647 | write32(spi + OPMENU0, cfg.opmenu[0]); |
| 648 | write32(spi + OPMENU1, cfg.opmenu[1]); |
| 649 | write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN); |
| 650 | write32(spi + UVSCC, cfg.uvscc); |
| 651 | write32(spi + LVSCC, cfg.lvscc | VCL); |
| 652 | } |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 653 | spi_init(); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 654 | |
| 655 | printk(BIOS_DEBUG, "Finalizing SMM.\n"); |
| 656 | outb(APM_CNT_FINALIZE, APM_CNT); |
| 657 | } |
| 658 | |
Hannah Williams | 2cfdde7 | 2015-04-15 19:48:07 -0700 | [diff] [blame] | 659 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL); |