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