Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 2 | |
| 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 5 | #include <arch/ioapic.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 6 | #include <assert.h> |
| 7 | #include <console/console.h> |
| 8 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 9 | #include <device/pci_ops.h> |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 10 | #include <intelblocks/gpmr.h> |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 11 | #include <intelblocks/itss.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 12 | #include <intelblocks/lpc_lib.h> |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 13 | #include <intelblocks/pcr.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 14 | #include <lib.h> |
| 15 | #include "lpc_def.h" |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 16 | #include <soc/irq.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 17 | #include <soc/pci_devs.h> |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 18 | #include <soc/pcr_ids.h> |
Tim Wawrzynczak | 0dc82cc | 2021-02-04 17:04:24 -0700 | [diff] [blame] | 19 | #include <southbridge/intel/common/acpi_pirq_gen.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 20 | |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 21 | uint16_t lpc_enable_fixed_io_ranges(uint16_t io_enables) |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 22 | { |
| 23 | uint16_t reg_io_enables; |
| 24 | |
| 25 | reg_io_enables = pci_read_config16(PCH_DEV_LPC, LPC_IO_ENABLES); |
| 26 | io_enables |= reg_io_enables; |
| 27 | pci_write_config16(PCH_DEV_LPC, LPC_IO_ENABLES, io_enables); |
Subrata Banik | 32e1022 | 2022-04-13 12:06:39 +0530 | [diff] [blame] | 28 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_GPMR)) |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 29 | gpmr_write32(GPMR_LPCIOE, io_enables); |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 30 | |
| 31 | return io_enables; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Wim Vervoorn | e6db910 | 2020-02-03 14:57:40 +0100 | [diff] [blame] | 34 | uint16_t lpc_get_fixed_io_decode(void) |
| 35 | { |
| 36 | return pci_read_config16(PCH_DEV_LPC, LPC_IO_DECODE); |
| 37 | } |
| 38 | |
Wim Vervoorn | 5f2adfe | 2020-02-03 15:32:54 +0100 | [diff] [blame] | 39 | uint16_t lpc_set_fixed_io_ranges(uint16_t io_ranges, uint16_t mask) |
| 40 | { |
| 41 | uint16_t reg_io_ranges; |
| 42 | |
| 43 | reg_io_ranges = lpc_get_fixed_io_decode() & ~mask; |
| 44 | io_ranges |= reg_io_ranges & mask; |
| 45 | pci_write_config16(PCH_DEV_LPC, LPC_IO_DECODE, io_ranges); |
Subrata Banik | 32e1022 | 2022-04-13 12:06:39 +0530 | [diff] [blame] | 46 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_GPMR)) |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 47 | gpmr_write32(GPMR_LPCIOD, io_ranges); |
Wim Vervoorn | 5f2adfe | 2020-02-03 15:32:54 +0100 | [diff] [blame] | 48 | |
| 49 | return io_ranges; |
| 50 | } |
| 51 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Find the first unused IO window. |
| 54 | * Returns -1 if not found, 0 for reg 0x84, 1 for reg 0x88 ... |
| 55 | */ |
| 56 | static int find_unused_pmio_window(void) |
| 57 | { |
| 58 | int i; |
| 59 | uint32_t lgir; |
| 60 | |
| 61 | for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) { |
| 62 | lgir = pci_read_config32(PCH_DEV_LPC, LPC_GENERIC_IO_RANGE(i)); |
| 63 | |
| 64 | if (!(lgir & LPC_LGIR_EN)) |
| 65 | return i; |
| 66 | } |
| 67 | |
| 68 | return -1; |
| 69 | } |
| 70 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 71 | void lpc_open_pmio_window(uint16_t base, uint16_t size) |
| 72 | { |
Lijian Zhao | e6db189 | 2018-04-13 16:27:38 -0700 | [diff] [blame] | 73 | int i, lgir_reg_num; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 74 | uint32_t lgir_reg_offset, lgir, window_size, alignment; |
| 75 | resource_t bridged_size, bridge_base; |
| 76 | |
Arthur Heymans | e4459b3 | 2022-06-11 16:56:24 +0200 | [diff] [blame] | 77 | switch (base) { |
| 78 | case 0: |
| 79 | printk(BIOS_ERR, "LPC IO decode base 0!\n"); |
| 80 | return; |
| 81 | case 0x2e: |
| 82 | case 0x2f: |
| 83 | if (size > 2) |
| 84 | break; |
| 85 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_SUPERIO_2E_2F\n"); |
| 86 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_SUPERIO_2E_2F); |
| 87 | return; |
| 88 | case 0x4e: |
| 89 | case 0x4f: |
| 90 | if (size > 2) |
| 91 | break; |
| 92 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_EC_4E_4F\n"); |
| 93 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_EC_4E_4F); |
| 94 | return; |
| 95 | case 0x60: |
| 96 | case 0x64: |
| 97 | if (size > 1) |
| 98 | break; |
| 99 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_KBC_60_64\n"); |
| 100 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_KBC_60_64); |
| 101 | return; |
| 102 | case 0x62: |
| 103 | case 0x66: |
| 104 | if (size > 1) |
| 105 | break; |
| 106 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_EC_62_66\n"); |
| 107 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_EC_62_66); |
| 108 | return; |
| 109 | case 0x200: |
| 110 | if (size > 8) |
| 111 | break; |
| 112 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_LGE_200\n"); |
| 113 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_LGE_200); |
| 114 | return; |
| 115 | case 0x208: |
| 116 | if (size > 8) |
| 117 | break; |
| 118 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_HGE_208\n"); |
| 119 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_HGE_208); |
| 120 | return; |
| 121 | case 0x2f8: /* Don't support secondary ranges */ |
| 122 | if (size > 8) |
| 123 | break; |
| 124 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_COMB_EN\n"); |
| 125 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_COMB_EN); |
| 126 | pci_update_config16(PCH_DEV_LPC, LPC_IO_DECODE, ~LPC_IOD_COMB_RANGE_MASK, |
| 127 | LPC_IOD_COMB_RANGE); |
| 128 | return; |
| 129 | case 0x378: /* Don't support secondary ranges */ |
| 130 | if (size > 8) |
| 131 | break; |
| 132 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_LPT_EN\n"); |
| 133 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_HGE_208); |
| 134 | pci_update_config16(PCH_DEV_LPC, LPC_IO_DECODE, ~LPC_IOD_LPT_RANGE_MASK, |
| 135 | LPC_IOD_LPT_RANGE); |
| 136 | return; |
| 137 | case 0x3f0: /* Don't support secondary ranges */ |
| 138 | if (size > 8) |
| 139 | break; |
| 140 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_FDD_EN\n"); |
| 141 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_FDD_EN); |
| 142 | pci_update_config16(PCH_DEV_LPC, LPC_IO_DECODE, ~LPC_IOD_FDD_RANGE_MASK, |
| 143 | LPC_IOD_FDD_RANGE); |
| 144 | return; |
| 145 | case 0x3f8: /* Don't support secondary ranges */ |
| 146 | if (size > 8) |
| 147 | break; |
| 148 | printk(BIOS_DEBUG, "LPC: enabling default decode range LPC_IOE_COMA_EN\n"); |
| 149 | pci_or_config16(PCH_DEV_LPC, LPC_IO_ENABLES, LPC_IOE_COMA_EN); |
| 150 | pci_update_config16(PCH_DEV_LPC, LPC_IO_DECODE, ~LPC_IOD_COMA_RANGE_MASK, |
| 151 | LPC_IOD_COMA_RANGE); |
| 152 | return; |
| 153 | } |
| 154 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 155 | printk(BIOS_SPEW, "LPC: Trying to open IO window from %x size %x\n", |
| 156 | base, size); |
| 157 | |
| 158 | bridged_size = 0; |
| 159 | bridge_base = base; |
| 160 | |
| 161 | while (bridged_size < size) { |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 162 | /* Each IO range register can only open a 256-byte window. */ |
| 163 | window_size = MIN(size, LPC_LGIR_MAX_WINDOW_SIZE); |
| 164 | |
John Zhao | 1ceac4e | 2019-07-09 14:27:28 -0700 | [diff] [blame] | 165 | if (window_size <= 0) |
John Zhao | 2bb432e | 2019-05-21 19:32:51 -0700 | [diff] [blame] | 166 | return; |
| 167 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 168 | /* Window size must be a power of two for the AMASK to work. */ |
Paul Menzel | fa7d2a0 | 2017-10-27 15:54:26 +0200 | [diff] [blame] | 169 | alignment = 1UL << (log2_ceil(window_size)); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 170 | window_size = ALIGN_UP(window_size, alignment); |
| 171 | |
| 172 | /* Address[15:2] in LGIR[15:12] and Mask[7:2] in LGIR[23:18]. */ |
| 173 | lgir = (bridge_base & LPC_LGIR_ADDR_MASK) | LPC_LGIR_EN; |
| 174 | lgir |= ((window_size - 1) << 16) & LPC_LGIR_AMASK_MASK; |
| 175 | |
Lijian Zhao | e6db189 | 2018-04-13 16:27:38 -0700 | [diff] [blame] | 176 | /* Skip programming if same range already programmed. */ |
| 177 | for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) { |
| 178 | if (lgir == pci_read_config32(PCH_DEV_LPC, |
| 179 | LPC_GENERIC_IO_RANGE(i))) |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | lgir_reg_num = find_unused_pmio_window(); |
| 184 | if (lgir_reg_num < 0) { |
| 185 | printk(BIOS_ERR, |
| 186 | "LPC: Cannot open IO window: %llx size %llx\n", |
| 187 | bridge_base, size - bridged_size); |
| 188 | printk(BIOS_ERR, "No more IO windows\n"); |
| 189 | return; |
| 190 | } |
| 191 | lgir_reg_offset = LPC_GENERIC_IO_RANGE(lgir_reg_num); |
| 192 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 193 | pci_write_config32(PCH_DEV_LPC, lgir_reg_offset, lgir); |
Subrata Banik | 32e1022 | 2022-04-13 12:06:39 +0530 | [diff] [blame] | 194 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_GPMR)) |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 195 | gpmr_write32(GPMR_LPCLGIR1 + lgir_reg_num * 4, lgir); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 196 | |
| 197 | printk(BIOS_DEBUG, |
| 198 | "LPC: Opened IO window LGIR%d: base %llx size %x\n", |
| 199 | lgir_reg_num, bridge_base, window_size); |
| 200 | |
| 201 | bridged_size += window_size; |
| 202 | bridge_base += window_size; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | void lpc_open_mmio_window(uintptr_t base, size_t size) |
| 207 | { |
| 208 | uint32_t lgmr; |
| 209 | |
| 210 | lgmr = pci_read_config32(PCH_DEV_LPC, LPC_GENERIC_MEM_RANGE); |
| 211 | |
| 212 | if (lgmr & LPC_LGMR_EN) { |
| 213 | printk(BIOS_ERR, |
| 214 | "LPC: Cannot open window to resource %lx size %zx\n", |
| 215 | base, size); |
| 216 | printk(BIOS_ERR, "LPC: MMIO window already in use\n"); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | if (size > LPC_LGMR_WINDOW_SIZE) { |
| 221 | printk(BIOS_WARNING, |
| 222 | "LPC: Resource %lx size %zx larger than window(%x)\n", |
| 223 | base, size, LPC_LGMR_WINDOW_SIZE); |
| 224 | } |
| 225 | |
| 226 | lgmr = (base & LPC_LGMR_ADDR_MASK) | LPC_LGMR_EN; |
| 227 | |
| 228 | pci_write_config32(PCH_DEV_LPC, LPC_GENERIC_MEM_RANGE, lgmr); |
Subrata Banik | 32e1022 | 2022-04-13 12:06:39 +0530 | [diff] [blame] | 229 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_GPMR)) |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 230 | gpmr_write32(GPMR_LPCGMR, lgmr); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 233 | /* |
Subrata Banik | 6b888ad | 2022-04-14 13:29:50 +0530 | [diff] [blame] | 234 | * Set LPC BIOS Control register based on input bit field. |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 235 | */ |
| 236 | static void lpc_set_bios_control_reg(uint8_t bios_cntl_bit) |
| 237 | { |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 238 | pci_devfn_t dev = PCH_DEV_LPC; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 239 | uint8_t bc_cntl; |
| 240 | |
Jonathan Neuschäfer | 3a182f7 | 2017-09-23 17:09:36 +0200 | [diff] [blame] | 241 | assert(IS_POWER_OF_2(bios_cntl_bit)); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 242 | bc_cntl = pci_read_config8(dev, LPC_BIOS_CNTL); |
| 243 | bc_cntl |= bios_cntl_bit; |
| 244 | pci_write_config8(dev, LPC_BIOS_CNTL, bc_cntl); |
| 245 | |
| 246 | /* |
| 247 | * Ensure an additional read back after performing lock down |
| 248 | */ |
| 249 | pci_read_config8(PCH_DEV_LPC, LPC_BIOS_CNTL); |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * Set LPC BIOS Control BILD bit. |
| 254 | */ |
| 255 | void lpc_set_bios_interface_lock_down(void) |
| 256 | { |
| 257 | lpc_set_bios_control_reg(LPC_BC_BILD); |
| 258 | } |
| 259 | |
| 260 | /* |
| 261 | * Set LPC BIOS Control LE bit. |
| 262 | */ |
| 263 | void lpc_set_lock_enable(void) |
| 264 | { |
| 265 | lpc_set_bios_control_reg(LPC_BC_LE); |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * Set LPC BIOS Control EISS bit. |
| 270 | */ |
| 271 | void lpc_set_eiss(void) |
| 272 | { |
| 273 | lpc_set_bios_control_reg(LPC_BC_EISS); |
| 274 | } |
| 275 | |
Subrata Banik | 77334d4 | 2022-04-18 11:30:38 +0530 | [diff] [blame] | 276 | static void lpc_configure_write_protect(bool status) |
| 277 | { |
| 278 | const pci_devfn_t dev = PCH_DEV_LPC; |
| 279 | uint8_t bios_cntl; |
| 280 | |
| 281 | bios_cntl = pci_read_config8(dev, LPC_BIOS_CNTL); |
| 282 | if (status) |
| 283 | bios_cntl &= ~LPC_BC_WPD; |
| 284 | else |
| 285 | bios_cntl |= LPC_BC_WPD; |
| 286 | pci_write_config8(dev, LPC_BIOS_CNTL, bios_cntl); |
| 287 | } |
| 288 | |
| 289 | /* Enable LPC Write Protect. */ |
| 290 | void lpc_enable_wp(void) |
| 291 | { |
| 292 | lpc_configure_write_protect(true); |
| 293 | } |
| 294 | |
| 295 | /* Disable LPC Write Protect. */ |
| 296 | void lpc_disable_wp(void) |
| 297 | { |
| 298 | lpc_configure_write_protect(false); |
| 299 | } |
| 300 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 301 | /* |
| 302 | * Set LPC Serial IRQ mode. |
| 303 | */ |
| 304 | void lpc_set_serirq_mode(enum serirq_mode mode) |
| 305 | { |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 306 | pci_devfn_t dev = PCH_DEV_LPC; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 307 | uint8_t scnt; |
| 308 | |
| 309 | scnt = pci_read_config8(dev, LPC_SERIRQ_CTL); |
| 310 | scnt &= ~(LPC_SCNT_EN | LPC_SCNT_MODE); |
| 311 | |
| 312 | switch (mode) { |
| 313 | case SERIRQ_QUIET: |
| 314 | scnt |= LPC_SCNT_EN; |
| 315 | break; |
| 316 | case SERIRQ_CONTINUOUS: |
| 317 | scnt |= LPC_SCNT_EN | LPC_SCNT_MODE; |
| 318 | break; |
| 319 | case SERIRQ_OFF: |
| 320 | default: |
| 321 | break; |
| 322 | } |
| 323 | |
| 324 | pci_write_config8(dev, LPC_SERIRQ_CTL, scnt); |
| 325 | } |
| 326 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 327 | void lpc_io_setup_comm_a_b(void) |
| 328 | { |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 329 | /* ComA Range 3F8h-3FFh [2:0] */ |
| 330 | uint16_t com_ranges = LPC_IOD_COMA_RANGE; |
| 331 | uint16_t com_enable = LPC_IOE_COMA_EN; |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 332 | uint16_t com_mask = LPC_IOD_COMA_RANGE_MASK; |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 333 | |
| 334 | /* ComB Range 2F8h-2FFh [6:4] */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 335 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_COMB_ENABLE)) { |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 336 | com_ranges |= LPC_IOD_COMB_RANGE; |
| 337 | com_enable |= LPC_IOE_COMB_EN; |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 338 | com_mask |= LPC_IOD_COMB_RANGE_MASK; |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /* Setup I/O Decode Range Register for LPC */ |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 342 | lpc_set_fixed_io_ranges(com_ranges, com_mask); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 343 | /* Enable ComA and ComB Port */ |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 344 | lpc_enable_fixed_io_ranges(com_enable); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 345 | } |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 346 | |
| 347 | static void lpc_set_gen_decode_range( |
| 348 | uint32_t gen_io_dec[LPC_NUM_GENERIC_IO_RANGES]) |
| 349 | { |
| 350 | size_t i; |
| 351 | |
| 352 | /* Set in PCI generic decode range registers */ |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 353 | for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) { |
| 354 | pci_write_config32(PCH_DEV_LPC, LPC_GENERIC_IO_RANGE(i), gen_io_dec[i]); |
Subrata Banik | 32e1022 | 2022-04-13 12:06:39 +0530 | [diff] [blame] | 355 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_GPMR)) |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 356 | gpmr_write32(GPMR_LPCLGIR1 + i * 4, gen_io_dec[i]); |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 357 | } |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 360 | void pch_enable_lpc(void) |
| 361 | { |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 362 | uint32_t gen_io_dec[LPC_NUM_GENERIC_IO_RANGES]; |
| 363 | |
Furquan Shaikh | e4f7e04 | 2020-12-23 14:11:00 -0800 | [diff] [blame] | 364 | soc_get_gen_io_dec_range(gen_io_dec); |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 365 | lpc_set_gen_decode_range(gen_io_dec); |
Subrata Banik | 42c44c2 | 2019-05-15 20:27:04 +0530 | [diff] [blame] | 366 | if (ENV_PAYLOAD_LOADER) |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 367 | pch_pirq_init(); |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void lpc_enable_pci_clk_cntl(void) |
| 371 | { |
| 372 | pci_write_config8(PCH_DEV_LPC, LPC_PCCTL, LPC_PCCTL_CLKRUN_EN); |
| 373 | } |
Nico Huber | dbcf293 | 2018-11-28 15:29:00 +0100 | [diff] [blame] | 374 | |
| 375 | void lpc_disable_clkrun(void) |
| 376 | { |
| 377 | const uint8_t pcctl = pci_read_config8(PCH_DEV_LPC, LPC_PCCTL); |
| 378 | pci_write_config8(PCH_DEV_LPC, LPC_PCCTL, pcctl & ~LPC_PCCTL_CLKRUN_EN); |
| 379 | } |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 380 | |
Kyösti Mälkki | 04a4037 | 2021-06-06 08:04:28 +0300 | [diff] [blame] | 381 | /* PCH I/O APIC redirection entries */ |
| 382 | #define PCH_REDIR_ETR 120 |
| 383 | |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 384 | /* Enable PCH IOAPIC */ |
| 385 | void pch_enable_ioapic(void) |
| 386 | { |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 387 | /* affirm full set of redirection table entries ("write once") */ |
Kyösti Mälkki | 04a4037 | 2021-06-06 08:04:28 +0300 | [diff] [blame] | 388 | ioapic_set_max_vectors(VIO_APIC_VADDR, PCH_REDIR_ETR); |
Kyösti Mälkki | ea6d12a | 2021-06-08 11:25:29 +0300 | [diff] [blame] | 389 | |
Kyösti Mälkki | 682613f | 2021-06-08 11:31:19 +0300 | [diff] [blame] | 390 | setup_ioapic((void *)IO_APIC_ADDR, 0x02); |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 391 | } |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 392 | |
Tim Wawrzynczak | 0dc82cc | 2021-02-04 17:04:24 -0700 | [diff] [blame] | 393 | static const uint8_t pch_interrupt_routing[PIRQ_COUNT] = { |
Tim Wawrzynczak | ef16df2 | 2021-06-05 11:38:14 -0600 | [diff] [blame] | 394 | [0] = PCH_IRQ11, /* PIRQ_A */ |
| 395 | [1] = PCH_IRQ10, /* PIRQ_B */ |
| 396 | [2] = PCH_IRQ11, /* PIRQ_C */ |
| 397 | [3] = PCH_IRQ11, /* PIRQ_D */ |
| 398 | [4] = PCH_IRQ11, /* PIRQ_E */ |
| 399 | [5] = PCH_IRQ11, /* PIRQ_F */ |
| 400 | [6] = PCH_IRQ11, /* PIRQ_G */ |
| 401 | [7] = PCH_IRQ11, /* PIRQ_H */ |
Tim Wawrzynczak | 0dc82cc | 2021-02-04 17:04:24 -0700 | [diff] [blame] | 402 | }; |
| 403 | |
| 404 | const uint8_t *lpc_get_pic_pirq_routing(size_t *num) |
| 405 | { |
| 406 | *num = ARRAY_SIZE(pch_interrupt_routing); |
| 407 | return pch_interrupt_routing; |
| 408 | } |
| 409 | |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 410 | /* |
| 411 | * PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 412 | * 0x00 - 0000 = Reserved |
| 413 | * 0x01 - 0001 = Reserved |
| 414 | * 0x02 - 0010 = Reserved |
| 415 | * 0x03 - 0011 = IRQ3 |
| 416 | * 0x04 - 0100 = IRQ4 |
| 417 | * 0x05 - 0101 = IRQ5 |
| 418 | * 0x06 - 0110 = IRQ6 |
| 419 | * 0x07 - 0111 = IRQ7 |
| 420 | * 0x08 - 1000 = Reserved |
| 421 | * 0x09 - 1001 = IRQ9 |
| 422 | * 0x0A - 1010 = IRQ10 |
| 423 | * 0x0B - 1011 = IRQ11 |
| 424 | * 0x0C - 1100 = IRQ12 |
| 425 | * 0x0D - 1101 = Reserved |
| 426 | * 0x0E - 1110 = IRQ14 |
| 427 | * 0x0F - 1111 = IRQ15 |
| 428 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 429 | * 0x80 - The PIRQ is not routed. |
| 430 | */ |
| 431 | void pch_pirq_init(void) |
| 432 | { |
| 433 | const struct device *irq_dev; |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 434 | itss_irq_init(pch_interrupt_routing); |
| 435 | |
| 436 | for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 437 | uint8_t int_pin = 0, int_line = 0; |
| 438 | |
| 439 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 440 | continue; |
| 441 | |
| 442 | int_pin = pci_read_config8(PCI_BDF(irq_dev), PCI_INTERRUPT_PIN); |
| 443 | |
| 444 | switch (int_pin) { |
| 445 | case 1: /* INTA# */ |
| 446 | int_line = PCH_IRQ11; |
| 447 | break; |
| 448 | case 2: /* INTB# */ |
| 449 | int_line = PCH_IRQ10; |
| 450 | break; |
| 451 | case 3: /* INTC# */ |
| 452 | int_line = PCH_IRQ11; |
| 453 | break; |
| 454 | case 4: /* INTD# */ |
| 455 | int_line = PCH_IRQ11; |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | if (!int_line) |
| 460 | continue; |
| 461 | |
| 462 | pci_write_config8(PCI_BDF(irq_dev), PCI_INTERRUPT_LINE, int_line); |
| 463 | } |
| 464 | } |
Subrata Banik | 8971ccd | 2020-09-29 14:36:40 +0530 | [diff] [blame] | 465 | |
| 466 | #define PPI_PORT_B 0x61 |
| 467 | #define SERR_DIS (1 << 2) |
| 468 | #define CMOS_NMI 0x70 |
| 469 | #define NMI_DIS (1 << 7) |
| 470 | |
| 471 | /* LPC MISC programming */ |
| 472 | void pch_misc_init(void) |
| 473 | { |
| 474 | uint8_t reg8; |
| 475 | |
| 476 | /* Setup NMI on errors, disable SERR */ |
| 477 | reg8 = (inb(PPI_PORT_B)) & 0xf0; |
| 478 | outb((reg8 | SERR_DIS), PPI_PORT_B); |
| 479 | |
| 480 | /* Disable NMI sources */ |
| 481 | outb(NMI_DIS, CMOS_NMI); |
| 482 | } |