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 | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 10 | #include <intelblocks/itss.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 11 | #include <intelblocks/lpc_lib.h> |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 12 | #include <intelblocks/pcr.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 13 | #include <lib.h> |
| 14 | #include "lpc_def.h" |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 15 | #include <soc/irq.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 16 | #include <soc/pci_devs.h> |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 17 | #include <soc/pcr_ids.h> |
Tim Wawrzynczak | 0dc82cc | 2021-02-04 17:04:24 -0700 | [diff] [blame] | 18 | #include <southbridge/intel/common/acpi_pirq_gen.h> |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 19 | |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 20 | uint16_t lpc_enable_fixed_io_ranges(uint16_t io_enables) |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 21 | { |
| 22 | uint16_t reg_io_enables; |
| 23 | |
| 24 | reg_io_enables = pci_read_config16(PCH_DEV_LPC, LPC_IO_ENABLES); |
| 25 | io_enables |= reg_io_enables; |
| 26 | pci_write_config16(PCH_DEV_LPC, LPC_IO_ENABLES, io_enables); |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 27 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_DMI)) |
| 28 | pcr_write16(PID_DMI, PCR_DMI_LPCIOE, io_enables); |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 29 | |
| 30 | return io_enables; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Wim Vervoorn | e6db910 | 2020-02-03 14:57:40 +0100 | [diff] [blame] | 33 | uint16_t lpc_get_fixed_io_decode(void) |
| 34 | { |
| 35 | return pci_read_config16(PCH_DEV_LPC, LPC_IO_DECODE); |
| 36 | } |
| 37 | |
Wim Vervoorn | 5f2adfe | 2020-02-03 15:32:54 +0100 | [diff] [blame] | 38 | uint16_t lpc_set_fixed_io_ranges(uint16_t io_ranges, uint16_t mask) |
| 39 | { |
| 40 | uint16_t reg_io_ranges; |
| 41 | |
| 42 | reg_io_ranges = lpc_get_fixed_io_decode() & ~mask; |
| 43 | io_ranges |= reg_io_ranges & mask; |
| 44 | pci_write_config16(PCH_DEV_LPC, LPC_IO_DECODE, io_ranges); |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 45 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_DMI)) |
| 46 | pcr_write16(PID_DMI, PCR_DMI_LPCIOD, io_ranges); |
Wim Vervoorn | 5f2adfe | 2020-02-03 15:32:54 +0100 | [diff] [blame] | 47 | |
| 48 | return io_ranges; |
| 49 | } |
| 50 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Find the first unused IO window. |
| 53 | * Returns -1 if not found, 0 for reg 0x84, 1 for reg 0x88 ... |
| 54 | */ |
| 55 | static int find_unused_pmio_window(void) |
| 56 | { |
| 57 | int i; |
| 58 | uint32_t lgir; |
| 59 | |
| 60 | for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) { |
| 61 | lgir = pci_read_config32(PCH_DEV_LPC, LPC_GENERIC_IO_RANGE(i)); |
| 62 | |
| 63 | if (!(lgir & LPC_LGIR_EN)) |
| 64 | return i; |
| 65 | } |
| 66 | |
| 67 | return -1; |
| 68 | } |
| 69 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 70 | void lpc_open_pmio_window(uint16_t base, uint16_t size) |
| 71 | { |
Lijian Zhao | e6db189 | 2018-04-13 16:27:38 -0700 | [diff] [blame] | 72 | int i, lgir_reg_num; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 73 | uint32_t lgir_reg_offset, lgir, window_size, alignment; |
| 74 | resource_t bridged_size, bridge_base; |
| 75 | |
| 76 | printk(BIOS_SPEW, "LPC: Trying to open IO window from %x size %x\n", |
| 77 | base, size); |
| 78 | |
| 79 | bridged_size = 0; |
| 80 | bridge_base = base; |
| 81 | |
| 82 | while (bridged_size < size) { |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 83 | /* Each IO range register can only open a 256-byte window. */ |
| 84 | window_size = MIN(size, LPC_LGIR_MAX_WINDOW_SIZE); |
| 85 | |
John Zhao | 1ceac4e | 2019-07-09 14:27:28 -0700 | [diff] [blame] | 86 | if (window_size <= 0) |
John Zhao | 2bb432e | 2019-05-21 19:32:51 -0700 | [diff] [blame] | 87 | return; |
| 88 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 89 | /* 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] | 90 | alignment = 1UL << (log2_ceil(window_size)); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 91 | window_size = ALIGN_UP(window_size, alignment); |
| 92 | |
| 93 | /* Address[15:2] in LGIR[15:12] and Mask[7:2] in LGIR[23:18]. */ |
| 94 | lgir = (bridge_base & LPC_LGIR_ADDR_MASK) | LPC_LGIR_EN; |
| 95 | lgir |= ((window_size - 1) << 16) & LPC_LGIR_AMASK_MASK; |
| 96 | |
Lijian Zhao | e6db189 | 2018-04-13 16:27:38 -0700 | [diff] [blame] | 97 | /* Skip programming if same range already programmed. */ |
| 98 | for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) { |
| 99 | if (lgir == pci_read_config32(PCH_DEV_LPC, |
| 100 | LPC_GENERIC_IO_RANGE(i))) |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | lgir_reg_num = find_unused_pmio_window(); |
| 105 | if (lgir_reg_num < 0) { |
| 106 | printk(BIOS_ERR, |
| 107 | "LPC: Cannot open IO window: %llx size %llx\n", |
| 108 | bridge_base, size - bridged_size); |
| 109 | printk(BIOS_ERR, "No more IO windows\n"); |
| 110 | return; |
| 111 | } |
| 112 | lgir_reg_offset = LPC_GENERIC_IO_RANGE(lgir_reg_num); |
| 113 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 114 | pci_write_config32(PCH_DEV_LPC, lgir_reg_offset, lgir); |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 115 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_DMI)) |
| 116 | pcr_write32(PID_DMI, PCR_DMI_LPCLGIR1 + lgir_reg_num * 4, lgir); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 117 | |
| 118 | printk(BIOS_DEBUG, |
| 119 | "LPC: Opened IO window LGIR%d: base %llx size %x\n", |
| 120 | lgir_reg_num, bridge_base, window_size); |
| 121 | |
| 122 | bridged_size += window_size; |
| 123 | bridge_base += window_size; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void lpc_open_mmio_window(uintptr_t base, size_t size) |
| 128 | { |
| 129 | uint32_t lgmr; |
| 130 | |
| 131 | lgmr = pci_read_config32(PCH_DEV_LPC, LPC_GENERIC_MEM_RANGE); |
| 132 | |
| 133 | if (lgmr & LPC_LGMR_EN) { |
| 134 | printk(BIOS_ERR, |
| 135 | "LPC: Cannot open window to resource %lx size %zx\n", |
| 136 | base, size); |
| 137 | printk(BIOS_ERR, "LPC: MMIO window already in use\n"); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | if (size > LPC_LGMR_WINDOW_SIZE) { |
| 142 | printk(BIOS_WARNING, |
| 143 | "LPC: Resource %lx size %zx larger than window(%x)\n", |
| 144 | base, size, LPC_LGMR_WINDOW_SIZE); |
| 145 | } |
| 146 | |
| 147 | lgmr = (base & LPC_LGMR_ADDR_MASK) | LPC_LGMR_EN; |
| 148 | |
| 149 | pci_write_config32(PCH_DEV_LPC, LPC_GENERIC_MEM_RANGE, lgmr); |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 150 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_DMI)) |
| 151 | pcr_write32(PID_DMI, PCR_DMI_LPCGMR, lgmr); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 154 | /* |
| 155 | * Set FAST_SPIBAR BIOS Control register based on input bit field. |
| 156 | */ |
| 157 | static void lpc_set_bios_control_reg(uint8_t bios_cntl_bit) |
| 158 | { |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 159 | pci_devfn_t dev = PCH_DEV_LPC; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 160 | uint8_t bc_cntl; |
| 161 | |
Jonathan Neuschäfer | 3a182f7 | 2017-09-23 17:09:36 +0200 | [diff] [blame] | 162 | assert(IS_POWER_OF_2(bios_cntl_bit)); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 163 | bc_cntl = pci_read_config8(dev, LPC_BIOS_CNTL); |
| 164 | bc_cntl |= bios_cntl_bit; |
| 165 | pci_write_config8(dev, LPC_BIOS_CNTL, bc_cntl); |
| 166 | |
| 167 | /* |
| 168 | * Ensure an additional read back after performing lock down |
| 169 | */ |
| 170 | pci_read_config8(PCH_DEV_LPC, LPC_BIOS_CNTL); |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Set LPC BIOS Control BILD bit. |
| 175 | */ |
| 176 | void lpc_set_bios_interface_lock_down(void) |
| 177 | { |
| 178 | lpc_set_bios_control_reg(LPC_BC_BILD); |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * Set LPC BIOS Control LE bit. |
| 183 | */ |
| 184 | void lpc_set_lock_enable(void) |
| 185 | { |
| 186 | lpc_set_bios_control_reg(LPC_BC_LE); |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Set LPC BIOS Control EISS bit. |
| 191 | */ |
| 192 | void lpc_set_eiss(void) |
| 193 | { |
| 194 | lpc_set_bios_control_reg(LPC_BC_EISS); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Set LPC Serial IRQ mode. |
| 199 | */ |
| 200 | void lpc_set_serirq_mode(enum serirq_mode mode) |
| 201 | { |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 202 | pci_devfn_t dev = PCH_DEV_LPC; |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 203 | uint8_t scnt; |
| 204 | |
| 205 | scnt = pci_read_config8(dev, LPC_SERIRQ_CTL); |
| 206 | scnt &= ~(LPC_SCNT_EN | LPC_SCNT_MODE); |
| 207 | |
| 208 | switch (mode) { |
| 209 | case SERIRQ_QUIET: |
| 210 | scnt |= LPC_SCNT_EN; |
| 211 | break; |
| 212 | case SERIRQ_CONTINUOUS: |
| 213 | scnt |= LPC_SCNT_EN | LPC_SCNT_MODE; |
| 214 | break; |
| 215 | case SERIRQ_OFF: |
| 216 | default: |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | pci_write_config8(dev, LPC_SERIRQ_CTL, scnt); |
| 221 | } |
| 222 | |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 223 | void lpc_io_setup_comm_a_b(void) |
| 224 | { |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 225 | /* ComA Range 3F8h-3FFh [2:0] */ |
| 226 | uint16_t com_ranges = LPC_IOD_COMA_RANGE; |
| 227 | uint16_t com_enable = LPC_IOE_COMA_EN; |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 228 | uint16_t com_mask = LPC_IOD_COMA_RANGE_MASK; |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 229 | |
| 230 | /* ComB Range 2F8h-2FFh [6:4] */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 231 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_COMB_ENABLE)) { |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 232 | com_ranges |= LPC_IOD_COMB_RANGE; |
| 233 | com_enable |= LPC_IOE_COMB_EN; |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 234 | com_mask |= LPC_IOD_COMB_RANGE_MASK; |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* Setup I/O Decode Range Register for LPC */ |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 238 | lpc_set_fixed_io_ranges(com_ranges, com_mask); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 239 | /* Enable ComA and ComB Port */ |
Subrata Banik | d83face | 2018-03-08 14:04:52 +0530 | [diff] [blame] | 240 | lpc_enable_fixed_io_ranges(com_enable); |
Ravi Sarawadi | efa606b | 2017-08-04 16:26:09 -0700 | [diff] [blame] | 241 | } |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 242 | |
| 243 | static void lpc_set_gen_decode_range( |
| 244 | uint32_t gen_io_dec[LPC_NUM_GENERIC_IO_RANGES]) |
| 245 | { |
| 246 | size_t i; |
| 247 | |
| 248 | /* Set in PCI generic decode range registers */ |
Michael Niewöhner | f7e91d2 | 2021-01-17 02:51:00 +0100 | [diff] [blame] | 249 | for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) { |
| 250 | pci_write_config32(PCH_DEV_LPC, LPC_GENERIC_IO_RANGE(i), gen_io_dec[i]); |
| 251 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_LPC_MIRROR_TO_DMI)) |
| 252 | pcr_write32(PID_DMI, PCR_DMI_LPCLGIR1 + i * 4, gen_io_dec[i]); |
| 253 | } |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 256 | void pch_enable_lpc(void) |
| 257 | { |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 258 | uint32_t gen_io_dec[LPC_NUM_GENERIC_IO_RANGES]; |
| 259 | |
Furquan Shaikh | e4f7e04 | 2020-12-23 14:11:00 -0800 | [diff] [blame] | 260 | soc_get_gen_io_dec_range(gen_io_dec); |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 261 | lpc_set_gen_decode_range(gen_io_dec); |
Subrata Banik | 42c44c2 | 2019-05-15 20:27:04 +0530 | [diff] [blame] | 262 | if (ENV_PAYLOAD_LOADER) |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 263 | pch_pirq_init(); |
Ravi Sarawadi | a9b5a39 | 2017-09-20 13:46:19 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void lpc_enable_pci_clk_cntl(void) |
| 267 | { |
| 268 | pci_write_config8(PCH_DEV_LPC, LPC_PCCTL, LPC_PCCTL_CLKRUN_EN); |
| 269 | } |
Nico Huber | dbcf293 | 2018-11-28 15:29:00 +0100 | [diff] [blame] | 270 | |
| 271 | void lpc_disable_clkrun(void) |
| 272 | { |
| 273 | const uint8_t pcctl = pci_read_config8(PCH_DEV_LPC, LPC_PCCTL); |
| 274 | pci_write_config8(PCH_DEV_LPC, LPC_PCCTL, pcctl & ~LPC_PCCTL_CLKRUN_EN); |
| 275 | } |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 276 | |
Kyösti Mälkki | 04a4037 | 2021-06-06 08:04:28 +0300 | [diff] [blame] | 277 | /* PCH I/O APIC redirection entries */ |
| 278 | #define PCH_REDIR_ETR 120 |
| 279 | |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 280 | /* Enable PCH IOAPIC */ |
| 281 | void pch_enable_ioapic(void) |
| 282 | { |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 283 | set_ioapic_id((void *)IO_APIC_ADDR, 0x02); |
| 284 | |
| 285 | /* affirm full set of redirection table entries ("write once") */ |
Kyösti Mälkki | 04a4037 | 2021-06-06 08:04:28 +0300 | [diff] [blame] | 286 | ioapic_set_max_vectors(VIO_APIC_VADDR, PCH_REDIR_ETR); |
Subrata Banik | 1366e44 | 2020-09-29 13:55:50 +0530 | [diff] [blame] | 287 | } |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 288 | |
Tim Wawrzynczak | 0dc82cc | 2021-02-04 17:04:24 -0700 | [diff] [blame] | 289 | static const uint8_t pch_interrupt_routing[PIRQ_COUNT] = { |
Tim Wawrzynczak | ef16df2 | 2021-06-05 11:38:14 -0600 | [diff] [blame] | 290 | [0] = PCH_IRQ11, /* PIRQ_A */ |
| 291 | [1] = PCH_IRQ10, /* PIRQ_B */ |
| 292 | [2] = PCH_IRQ11, /* PIRQ_C */ |
| 293 | [3] = PCH_IRQ11, /* PIRQ_D */ |
| 294 | [4] = PCH_IRQ11, /* PIRQ_E */ |
| 295 | [5] = PCH_IRQ11, /* PIRQ_F */ |
| 296 | [6] = PCH_IRQ11, /* PIRQ_G */ |
| 297 | [7] = PCH_IRQ11, /* PIRQ_H */ |
Tim Wawrzynczak | 0dc82cc | 2021-02-04 17:04:24 -0700 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | const uint8_t *lpc_get_pic_pirq_routing(size_t *num) |
| 301 | { |
| 302 | *num = ARRAY_SIZE(pch_interrupt_routing); |
| 303 | return pch_interrupt_routing; |
| 304 | } |
| 305 | |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 306 | /* |
| 307 | * PIRQ[n]_ROUT[3:0] - PIRQ Routing Control |
| 308 | * 0x00 - 0000 = Reserved |
| 309 | * 0x01 - 0001 = Reserved |
| 310 | * 0x02 - 0010 = Reserved |
| 311 | * 0x03 - 0011 = IRQ3 |
| 312 | * 0x04 - 0100 = IRQ4 |
| 313 | * 0x05 - 0101 = IRQ5 |
| 314 | * 0x06 - 0110 = IRQ6 |
| 315 | * 0x07 - 0111 = IRQ7 |
| 316 | * 0x08 - 1000 = Reserved |
| 317 | * 0x09 - 1001 = IRQ9 |
| 318 | * 0x0A - 1010 = IRQ10 |
| 319 | * 0x0B - 1011 = IRQ11 |
| 320 | * 0x0C - 1100 = IRQ12 |
| 321 | * 0x0D - 1101 = Reserved |
| 322 | * 0x0E - 1110 = IRQ14 |
| 323 | * 0x0F - 1111 = IRQ15 |
| 324 | * PIRQ[n]_ROUT[7] - PIRQ Routing Control |
| 325 | * 0x80 - The PIRQ is not routed. |
| 326 | */ |
| 327 | void pch_pirq_init(void) |
| 328 | { |
| 329 | const struct device *irq_dev; |
Subrata Banik | 78463a7 | 2020-09-29 14:28:09 +0530 | [diff] [blame] | 330 | itss_irq_init(pch_interrupt_routing); |
| 331 | |
| 332 | for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) { |
| 333 | uint8_t int_pin = 0, int_line = 0; |
| 334 | |
| 335 | if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI) |
| 336 | continue; |
| 337 | |
| 338 | int_pin = pci_read_config8(PCI_BDF(irq_dev), PCI_INTERRUPT_PIN); |
| 339 | |
| 340 | switch (int_pin) { |
| 341 | case 1: /* INTA# */ |
| 342 | int_line = PCH_IRQ11; |
| 343 | break; |
| 344 | case 2: /* INTB# */ |
| 345 | int_line = PCH_IRQ10; |
| 346 | break; |
| 347 | case 3: /* INTC# */ |
| 348 | int_line = PCH_IRQ11; |
| 349 | break; |
| 350 | case 4: /* INTD# */ |
| 351 | int_line = PCH_IRQ11; |
| 352 | break; |
| 353 | } |
| 354 | |
| 355 | if (!int_line) |
| 356 | continue; |
| 357 | |
| 358 | pci_write_config8(PCI_BDF(irq_dev), PCI_INTERRUPT_LINE, int_line); |
| 359 | } |
| 360 | } |
Subrata Banik | 8971ccd | 2020-09-29 14:36:40 +0530 | [diff] [blame] | 361 | |
| 362 | #define PPI_PORT_B 0x61 |
| 363 | #define SERR_DIS (1 << 2) |
| 364 | #define CMOS_NMI 0x70 |
| 365 | #define NMI_DIS (1 << 7) |
| 366 | |
| 367 | /* LPC MISC programming */ |
| 368 | void pch_misc_init(void) |
| 369 | { |
| 370 | uint8_t reg8; |
| 371 | |
| 372 | /* Setup NMI on errors, disable SERR */ |
| 373 | reg8 = (inb(PPI_PORT_B)) & 0xf0; |
| 374 | outb((reg8 | SERR_DIS), PPI_PORT_B); |
| 375 | |
| 376 | /* Disable NMI sources */ |
| 377 | outb(NMI_DIS, CMOS_NMI); |
| 378 | } |