Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
Felix Held | 390a280 | 2021-10-21 03:13:42 +0200 | [diff] [blame] | 3 | #include <arch/ioapic.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pnp.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 9 | #include <pc80/mc146818rtc.h> |
| 10 | #include <pc80/isa-dma.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 11 | #include <pc80/i8254.h> |
| 12 | #include <pc80/i8259.h> |
Raul E Rangel | 0f3bc81 | 2021-02-10 16:36:33 -0700 | [diff] [blame] | 13 | #include <amdblocks/acpi.h> |
Marshall Dawson | 69486ca | 2019-05-02 12:03:45 -0600 | [diff] [blame] | 14 | #include <amdblocks/acpimmio.h> |
Furquan Shaikh | 511aa44 | 2020-05-04 23:42:46 -0700 | [diff] [blame] | 15 | #include <amdblocks/espi.h> |
Felix Held | 390a280 | 2021-10-21 03:13:42 +0200 | [diff] [blame] | 16 | #include <amdblocks/ioapic.h> |
Felix Held | 199b10f | 2022-08-13 00:29:23 +0200 | [diff] [blame] | 17 | #include <amdblocks/iomap.h> |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 18 | #include <amdblocks/lpc.h> |
Kyösti Mälkki | e742b68 | 2023-04-10 17:03:32 +0300 | [diff] [blame] | 19 | #include <soc/acpi.h> |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 20 | #include <soc/iomap.h> |
Raul E Rangel | 466edb5 | 2021-02-09 11:24:13 -0700 | [diff] [blame] | 21 | #include <soc/lpc.h> |
| 22 | #include <soc/southbridge.h> |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 23 | |
Marshall Dawson | 8d9b878 | 2020-06-29 17:56:02 -0600 | [diff] [blame] | 24 | static void setup_serirq(void) |
| 25 | { |
| 26 | u8 byte; |
| 27 | |
| 28 | /* Set up SERIRQ, enable continuous mode */ |
Raul E Rangel | a91eb90 | 2021-02-24 16:26:34 -0700 | [diff] [blame] | 29 | byte = PM_SERIRQ_NUM_BITS_21; |
| 30 | if (!CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI)) |
| 31 | byte |= PM_SERIRQ_ENABLE; |
Marshall Dawson | 8d9b878 | 2020-06-29 17:56:02 -0600 | [diff] [blame] | 32 | if (!CONFIG(SERIRQ_CONTINUOUS_MODE)) |
| 33 | byte |= PM_SERIRQ_MODE; |
| 34 | |
| 35 | pm_write8(PM_SERIRQ_CONF, byte); |
| 36 | } |
| 37 | |
Kyösti Mälkki | e742b68 | 2023-04-10 17:03:32 +0300 | [diff] [blame] | 38 | void ioapic_get_sci_pin(u8 *gsi, u8 *irq, u8 *flags) |
| 39 | { |
| 40 | *gsi = ACPI_SCI_IRQ; |
| 41 | *irq = ACPI_SCI_IRQ; |
| 42 | *flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW; |
| 43 | } |
| 44 | |
Felix Held | 390a280 | 2021-10-21 03:13:42 +0200 | [diff] [blame] | 45 | static void fch_ioapic_init(void) |
| 46 | { |
| 47 | fch_enable_ioapic_decode(); |
Kyösti Mälkki | 2e65e9c | 2021-06-16 11:00:40 +0300 | [diff] [blame] | 48 | register_new_ioapic_gsi0(VIO_APIC_VADDR); |
Felix Held | 390a280 | 2021-10-21 03:13:42 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 51 | static void lpc_init(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 52 | { |
| 53 | u8 byte; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 54 | |
| 55 | /* Initialize isa dma */ |
| 56 | isa_dma_init(); |
| 57 | |
| 58 | /* Enable DMA transaction on the LPC bus */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 59 | byte = pci_read_config8(dev, LPC_PCI_CONTROL); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 60 | byte |= LEGACY_DMA_EN; |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 61 | pci_write_config8(dev, LPC_PCI_CONTROL, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 62 | |
| 63 | /* Disable the timeout mechanism on LPC */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 64 | byte = pci_read_config8(dev, LPC_IO_OR_MEM_DECODE_ENABLE); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 65 | byte &= ~LPC_SYNC_TIMEOUT_COUNT_ENABLE; |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 66 | pci_write_config8(dev, LPC_IO_OR_MEM_DECODE_ENABLE, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 67 | |
| 68 | /* Disable LPC MSI Capability */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 69 | byte = pci_read_config8(dev, LPC_MISC_CONTROL_BITS); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 70 | /* BIT 1 is not defined in public datasheet. */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 71 | byte &= ~(1 << 1); |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 72 | |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 73 | pci_write_config8(dev, LPC_MISC_CONTROL_BITS, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 74 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 75 | /* |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 76 | * Enable hand-instance of the pulse generator and SPI prefetch from |
| 77 | * host (earlier is recommended for boot speed). |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 78 | */ |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 79 | byte = pci_read_config8(dev, LPC_HOST_CONTROL); |
Richard Spiegel | ee09878 | 2018-07-30 12:05:22 -0700 | [diff] [blame] | 80 | byte |= PREFETCH_EN_SPI_FROM_HOST | T_START_ENH; |
Marshall Dawson | 1bc04e3 | 2019-05-02 18:56:54 -0600 | [diff] [blame] | 81 | pci_write_config8(dev, LPC_HOST_CONTROL, byte); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 82 | |
| 83 | cmos_check_update_date(); |
| 84 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 85 | /* |
| 86 | * Initialize the real time clock. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 87 | * The 0 argument tells cmos_init not to |
| 88 | * update CMOS unless it is invalid. |
| 89 | * 1 tells cmos_init to always initialize the CMOS. |
| 90 | */ |
Aaron Durbin | 9fde0d7 | 2017-09-15 11:01:17 -0600 | [diff] [blame] | 91 | cmos_init(0); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 92 | |
| 93 | /* Initialize i8259 pic */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 94 | setup_i8259(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 95 | |
| 96 | /* Initialize i8254 timers */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 97 | setup_i8254(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 98 | |
Raul E Rangel | a91eb90 | 2021-02-24 16:26:34 -0700 | [diff] [blame] | 99 | setup_serirq(); |
Felix Held | 390a280 | 2021-10-21 03:13:42 +0200 | [diff] [blame] | 100 | |
| 101 | fch_ioapic_init(); |
| 102 | fch_configure_hpet(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 103 | } |
| 104 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 105 | static void lpc_read_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 106 | { |
| 107 | struct resource *res; |
| 108 | |
| 109 | /* Get the normal pci resources of this device */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 110 | pci_dev_read_resources(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 111 | |
| 112 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 113 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 114 | res->base = 0; |
| 115 | res->size = 0x1000; |
| 116 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 117 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 118 | |
Felix Held | 199b10f | 2022-08-13 00:29:23 +0200 | [diff] [blame] | 119 | /* Only up to 16 MByte of the SPI flash can be mapped right below 4 GB */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 120 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
Felix Held | 199b10f | 2022-08-13 00:29:23 +0200 | [diff] [blame] | 121 | res->base = FLASH_BELOW_4GB_MAPPING_REGION_BASE; |
| 122 | res->size = FLASH_BELOW_4GB_MAPPING_REGION_SIZE; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 123 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 124 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 125 | |
| 126 | /* Add a memory resource for the SPI BAR. */ |
Kyösti Mälkki | 8b89424 | 2022-05-26 15:42:59 +0300 | [diff] [blame] | 127 | mmio_range(dev, 2, SPI_BASE_ADDRESS, 1 * KiB); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 128 | |
| 129 | res = new_resource(dev, 3); /* IOAPIC */ |
| 130 | res->base = IO_APIC_ADDR; |
| 131 | res->size = 0x00001000; |
| 132 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 133 | |
| 134 | compact_resources(dev); |
| 135 | } |
| 136 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 137 | static void lpc_set_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 138 | { |
| 139 | struct resource *res; |
| 140 | u32 spi_enable_bits; |
| 141 | |
| 142 | /* Special case. The SpiRomEnable and other enables should STAY set. */ |
| 143 | res = find_resource(dev, 2); |
Felix Held | 697fa74 | 2022-03-03 20:54:38 +0100 | [diff] [blame] | 144 | spi_enable_bits = pci_read_config32(dev, SPI_BASE_ADDRESS_REGISTER); |
Marshall Dawson | eceaa97 | 2019-05-05 18:35:12 -0600 | [diff] [blame] | 145 | spi_enable_bits &= SPI_BASE_ALIGNMENT - 1; |
Felix Held | 697fa74 | 2022-03-03 20:54:38 +0100 | [diff] [blame] | 146 | pci_write_config32(dev, SPI_BASE_ADDRESS_REGISTER, |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 147 | res->base | spi_enable_bits); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 148 | |
| 149 | pci_dev_set_resources(dev); |
| 150 | } |
| 151 | |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 152 | static void configure_child_lpc_windows(struct device *dev, struct device *child) |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 153 | { |
| 154 | struct resource *res; |
| 155 | u32 base, end; |
| 156 | u32 rsize = 0, set = 0, set_x = 0; |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 157 | int wideio_index; |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 158 | u32 reg, reg_x; |
| 159 | |
| 160 | reg = pci_read_config32(dev, LPC_IO_PORT_DECODE_ENABLE); |
| 161 | reg_x = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE); |
| 162 | |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 163 | /* |
| 164 | * Be a bit relaxed, tolerate that LPC region might be bigger than |
| 165 | * resource we try to fit, do it like this for all regions < 16 bytes. |
| 166 | * If there is a resource > 16 bytes it must be 512 bytes to be able |
| 167 | * to allocate the fresh LPC window. |
| 168 | * |
| 169 | * AGESA and early initialization can set a wide IO port. This code |
| 170 | * will verify if required region was previously set and will avoid |
| 171 | * setting a new wide IO resource if one is already set. |
| 172 | */ |
| 173 | |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 174 | for (res = child->resource_list; res; res = res->next) { |
| 175 | if (!(res->flags & IORESOURCE_IO)) |
| 176 | continue; |
| 177 | base = res->base; |
| 178 | end = resource_end(res); |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 179 | printk(BIOS_DEBUG, |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 180 | "Southbridge LPC decode:%s, base=0x%08x, end=0x%08x\n", |
| 181 | dev_path(child), base, end); |
| 182 | /* find a resource size */ |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 183 | switch (base) { |
| 184 | case 0x60: /* KB */ |
| 185 | case 0x64: /* MS */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 186 | set |= DECODE_ENABLE_KBC_PORT; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 187 | rsize = 1; |
| 188 | break; |
| 189 | case 0x3f8: /* COM1 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 190 | set |= DECODE_ENABLE_SERIAL_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 191 | rsize = 8; |
| 192 | break; |
| 193 | case 0x2f8: /* COM2 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 194 | set |= DECODE_ENABLE_SERIAL_PORT1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 195 | rsize = 8; |
| 196 | break; |
| 197 | case 0x378: /* Parallel 1 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 198 | set |= DECODE_ENABLE_PARALLEL_PORT0; |
| 199 | /* enable 0x778 for ECP mode */ |
| 200 | set |= DECODE_ENABLE_PARALLEL_PORT1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 201 | rsize = 8; |
| 202 | break; |
| 203 | case 0x3f0: /* FD0 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 204 | set |= DECODE_ENABLE_FDC_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 205 | rsize = 8; |
| 206 | break; |
| 207 | case 0x220: /* 0x220 - 0x227 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 208 | set |= DECODE_ENABLE_SERIAL_PORT2; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 209 | rsize = 8; |
| 210 | break; |
| 211 | case 0x228: /* 0x228 - 0x22f */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 212 | set |= DECODE_ENABLE_SERIAL_PORT3; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 213 | rsize = 8; |
| 214 | break; |
| 215 | case 0x238: /* 0x238 - 0x23f */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 216 | set |= DECODE_ENABLE_SERIAL_PORT4; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 217 | rsize = 8; |
| 218 | break; |
| 219 | case 0x300: /* 0x300 - 0x301 */ |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 220 | set |= DECODE_ENABLE_MIDI_PORT0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 221 | rsize = 2; |
| 222 | break; |
| 223 | case 0x400: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 224 | set_x |= DECODE_IO_PORT_ENABLE0; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 225 | rsize = 0x40; |
| 226 | break; |
| 227 | case 0x480: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 228 | set_x |= DECODE_IO_PORT_ENABLE1; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 229 | rsize = 0x40; |
| 230 | break; |
| 231 | case 0x500: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 232 | set_x |= DECODE_IO_PORT_ENABLE2; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 233 | rsize = 0x40; |
| 234 | break; |
| 235 | case 0x580: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 236 | set_x |= DECODE_IO_PORT_ENABLE3; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 237 | rsize = 0x40; |
| 238 | break; |
| 239 | case 0x4700: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 240 | set_x |= DECODE_IO_PORT_ENABLE5; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 241 | rsize = 0xc; |
| 242 | break; |
| 243 | case 0xfd60: |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 244 | set_x |= DECODE_IO_PORT_ENABLE6; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 245 | rsize = 16; |
| 246 | break; |
| 247 | default: |
| 248 | rsize = 0; |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 249 | wideio_index = lpc_find_wideio_range(base, res->size); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 250 | if (wideio_index != WIDEIO_RANGE_ERROR) { |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 251 | rsize = lpc_wideio_size(wideio_index); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 252 | printk(BIOS_DEBUG, "Covered by wideIO"); |
| 253 | printk(BIOS_DEBUG, " %d\n", wideio_index); |
Richard Spiegel | 7a39e02 | 2017-11-09 10:54:04 -0700 | [diff] [blame] | 254 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 255 | } |
| 256 | /* check if region found and matches the enable */ |
| 257 | if (res->size <= rsize) { |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 258 | reg |= set; |
| 259 | reg_x |= set_x; |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 260 | /* check if we can fit resource in variable range */ |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 261 | } else { |
Marshall Dawson | 6ab5ed3 | 2019-05-29 09:24:18 -0600 | [diff] [blame] | 262 | wideio_index = lpc_set_wideio_range(base, res->size); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 263 | if (wideio_index != WIDEIO_RANGE_ERROR) { |
| 264 | /* preserve wide IO related bits. */ |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 265 | reg_x = pci_read_config32(dev, |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 266 | LPC_IO_OR_MEM_DECODE_ENABLE); |
Richard Spiegel | b5f9645 | 2017-11-22 15:28:25 -0700 | [diff] [blame] | 267 | printk(BIOS_DEBUG, |
| 268 | "Range assigned to wide IO %d\n", |
| 269 | wideio_index); |
| 270 | } else { |
| 271 | printk(BIOS_ERR, |
| 272 | "cannot fit LPC decode region:"); |
| 273 | printk(BIOS_ERR, |
| 274 | "%s, base = 0x%08x, end = 0x%08x\n", |
| 275 | dev_path(child), base, end); |
| 276 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
Richard Spiegel | aa18385 | 2017-10-05 18:53:31 -0700 | [diff] [blame] | 279 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 280 | pci_write_config32(dev, LPC_IO_PORT_DECODE_ENABLE, reg); |
| 281 | pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, reg_x); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 282 | } |
| 283 | |
Furquan Shaikh | 511aa44 | 2020-05-04 23:42:46 -0700 | [diff] [blame] | 284 | static void configure_child_espi_windows(struct device *child) |
| 285 | { |
| 286 | struct resource *res; |
| 287 | |
| 288 | for (res = child->resource_list; res; res = res->next) { |
| 289 | if (res->flags & IORESOURCE_IO) |
| 290 | espi_open_io_window(res->base, res->size); |
| 291 | else if (res->flags & IORESOURCE_MEM) |
| 292 | espi_open_mmio_window(res->base, res->size); |
| 293 | } |
| 294 | } |
| 295 | |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 296 | static void lpc_enable_children_resources(struct device *dev) |
| 297 | { |
| 298 | struct bus *link; |
| 299 | struct device *child; |
| 300 | |
| 301 | for (link = dev->link_list; link; link = link->next) { |
| 302 | for (child = link->children; child; child = child->sibling) { |
| 303 | if (!child->enabled) |
| 304 | continue; |
| 305 | if (child->path.type != DEVICE_PATH_PNP) |
| 306 | continue; |
Furquan Shaikh | 511aa44 | 2020-05-04 23:42:46 -0700 | [diff] [blame] | 307 | if (CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI)) |
| 308 | configure_child_espi_windows(child); |
| 309 | else |
| 310 | configure_child_lpc_windows(dev, child); |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 315 | static void lpc_enable_resources(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 316 | { |
| 317 | pci_dev_enable_resources(dev); |
Furquan Shaikh | 1e279a5 | 2020-05-04 21:22:22 -0700 | [diff] [blame] | 318 | lpc_enable_children_resources(dev); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 319 | } |
| 320 | |
Felix Held | 3e29ca9 | 2021-02-16 23:52:58 +0100 | [diff] [blame] | 321 | #if CONFIG(HAVE_ACPI_TABLES) |
| 322 | static const char *lpc_acpi_name(const struct device *dev) |
| 323 | { |
| 324 | return "LPCB"; |
| 325 | } |
| 326 | #endif |
| 327 | |
Arthur Heymans | c6f029c | 2022-10-05 21:48:07 +0200 | [diff] [blame] | 328 | struct device_operations amd_lpc_ops = { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 329 | .read_resources = lpc_read_resources, |
| 330 | .set_resources = lpc_set_resources, |
| 331 | .enable_resources = lpc_enable_resources, |
Zheng Bao | bdd5031 | 2021-01-26 18:27:46 +0800 | [diff] [blame] | 332 | #if CONFIG(HAVE_ACPI_TABLES) |
Felix Held | 3e29ca9 | 2021-02-16 23:52:58 +0100 | [diff] [blame] | 333 | .acpi_name = lpc_acpi_name, |
Marc Jones | 257db58 | 2017-06-18 17:33:30 -0600 | [diff] [blame] | 334 | .write_acpi_tables = southbridge_write_acpi_tables, |
Zheng Bao | bdd5031 | 2021-01-26 18:27:46 +0800 | [diff] [blame] | 335 | #endif |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 336 | .init = lpc_init, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 337 | .scan_bus = scan_static_bus, |
Furquan Shaikh | 40454b7 | 2020-05-04 20:52:08 -0700 | [diff] [blame] | 338 | .ops_pci = &pci_dev_ops_pci, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 339 | }; |