Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 2 | |
Angel Pons | 24f4623 | 2021-04-17 12:08:15 +0200 | [diff] [blame] | 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 5 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 9 | #include <intelblocks/gpmr.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 10 | #include <intelblocks/pcr.h> |
Michael Niewöhner | 2bd2be5 | 2020-03-03 20:47:01 +0100 | [diff] [blame] | 11 | #include <intelblocks/pmclib.h> |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 12 | #include <intelblocks/tco.h> |
| 13 | #include <soc/iomap.h> |
| 14 | #include <soc/pci_devs.h> |
| 15 | #include <soc/pcr_ids.h> |
| 16 | #include <soc/pm.h> |
| 17 | #include <soc/smbus.h> |
| 18 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 19 | /* SMBUS TCO base address. */ |
| 20 | #define TCOBASE 0x50 |
| 21 | #define TCOCTL 0x54 |
| 22 | #define TCO_BASE_EN (1 << 8) |
Michael Niewöhner | 3c20cba | 2019-09-22 13:27:20 +0200 | [diff] [blame] | 23 | #define TCO_BASE_LOCK (1 << 0) |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 24 | |
| 25 | /* Get base address of TCO I/O registers. */ |
| 26 | static uint16_t tco_get_bar(void) |
| 27 | { |
| 28 | return TCO_BASE_ADDRESS; |
| 29 | } |
| 30 | |
| 31 | uint16_t tco_read_reg(uint16_t tco_reg) |
| 32 | { |
| 33 | uint16_t tcobase; |
| 34 | |
| 35 | tcobase = tco_get_bar(); |
| 36 | |
| 37 | return inw(tcobase + tco_reg); |
| 38 | } |
| 39 | |
| 40 | void tco_write_reg(uint16_t tco_reg, uint16_t value) |
| 41 | { |
| 42 | uint16_t tcobase; |
| 43 | |
| 44 | tcobase = tco_get_bar(); |
| 45 | |
| 46 | outw(value, tcobase + tco_reg); |
| 47 | } |
| 48 | |
| 49 | void tco_lockdown(void) |
| 50 | { |
| 51 | uint16_t tcocnt; |
Michael Niewöhner | 3c20cba | 2019-09-22 13:27:20 +0200 | [diff] [blame] | 52 | const pci_devfn_t dev = PCH_DEV_SMBUS; |
| 53 | |
| 54 | /* TCO base address lockdown */ |
| 55 | pci_or_config32(dev, TCOCTL, TCO_BASE_LOCK); |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 56 | |
| 57 | /* TCO Lock down */ |
| 58 | tcocnt = tco_read_reg(TCO1_CNT); |
| 59 | tcocnt |= TCO_LOCK; |
| 60 | tco_write_reg(TCO1_CNT, tcocnt); |
| 61 | } |
| 62 | |
| 63 | uint32_t tco_reset_status(void) |
| 64 | { |
| 65 | uint16_t tco1_sts; |
| 66 | uint16_t tco2_sts; |
| 67 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 68 | /* TCO Status 1 register */ |
| 69 | tco1_sts = tco_read_reg(TCO1_STS); |
Michael Niewöhner | 04b0206 | 2020-03-03 18:33:00 +0100 | [diff] [blame] | 70 | tco_write_reg(TCO1_STS, tco1_sts); |
| 71 | |
| 72 | /* TCO Status 2 register */ |
| 73 | tco2_sts = tco_read_reg(TCO2_STS); |
Kyösti Mälkki | 307320c | 2022-11-21 17:27:07 +0200 | [diff] [blame] | 74 | tco_write_reg(TCO2_STS, tco2_sts | TCO2_STS_SECOND_TO); |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 75 | |
| 76 | return (tco2_sts << 16) | tco1_sts; |
| 77 | } |
| 78 | |
| 79 | /* Stop TCO timer */ |
| 80 | static void tco_timer_disable(void) |
| 81 | { |
| 82 | uint16_t tcocnt; |
| 83 | |
| 84 | /* Program TCO timer halt */ |
| 85 | tcocnt = tco_read_reg(TCO1_CNT); |
| 86 | tcocnt |= TCO_TMR_HLT; |
| 87 | tco_write_reg(TCO1_CNT, tcocnt); |
| 88 | } |
| 89 | |
Michael Niewöhner | 2bd2be5 | 2020-03-03 20:47:01 +0100 | [diff] [blame] | 90 | /* Enable and initialize TCO intruder SMI */ |
| 91 | static void tco_intruder_smi_enable(void) |
| 92 | { |
| 93 | uint16_t tcocnt; |
| 94 | |
| 95 | /* Make TCO issue an SMI on INTRD_DET assertion */ |
| 96 | tcocnt = tco_read_reg(TCO2_CNT); |
| 97 | tcocnt &= ~TCO_INTRD_SEL_MASK; |
| 98 | tcocnt |= TCO_INTRD_SEL_SMI; |
| 99 | tco_write_reg(TCO2_CNT, tcocnt); |
| 100 | } |
| 101 | |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 102 | /* Enable TCO BAR using SMBUS TCO base to access TCO related register */ |
| 103 | static void tco_enable_bar(void) |
| 104 | { |
| 105 | uint32_t reg32; |
| 106 | uint16_t tcobase; |
Angel Pons | 24f4623 | 2021-04-17 12:08:15 +0200 | [diff] [blame] | 107 | const pci_devfn_t dev = PCH_DEV_SMBUS; |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 108 | |
| 109 | /* Disable TCO in SMBUS Device first before changing Base Address */ |
| 110 | reg32 = pci_read_config32(dev, TCOCTL); |
| 111 | reg32 &= ~TCO_BASE_EN; |
| 112 | pci_write_config32(dev, TCOCTL, reg32); |
| 113 | |
| 114 | /* Program TCO Base */ |
| 115 | tcobase = tco_get_bar(); |
| 116 | pci_write_config32(dev, TCOBASE, tcobase); |
| 117 | |
| 118 | /* Enable TCO in SMBUS */ |
| 119 | pci_write_config32(dev, TCOCTL, reg32 | TCO_BASE_EN); |
| 120 | |
Subrata Banik | 211be9c | 2022-04-13 12:13:09 +0530 | [diff] [blame] | 121 | /* Program TCO Base Address */ |
| 122 | gpmr_write32(GPMR_TCOBASE, tcobase | GPMR_TCOEN); |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Enable TCO BAR using SMBUS TCO base to access TCO related register |
| 127 | * also disable the timer. |
| 128 | */ |
| 129 | void tco_configure(void) |
| 130 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 131 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCO_ENABLE_THROUGH_SMBUS)) |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 132 | tco_enable_bar(); |
| 133 | |
| 134 | tco_timer_disable(); |
Michael Niewöhner | 2bd2be5 | 2020-03-03 20:47:01 +0100 | [diff] [blame] | 135 | |
| 136 | /* Enable intruder interrupt if TCO interrupts are enabled*/ |
| 137 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_SMM_TCO_ENABLE)) |
| 138 | tco_intruder_smi_enable(); |
Subrata Banik | 7bc4dc5 | 2018-05-17 18:40:32 +0530 | [diff] [blame] | 139 | } |