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