Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 2 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
Subrata Banik | 05e06cd | 2017-11-09 15:04:09 +0530 | [diff] [blame] | 5 | #include <assert.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 6 | #include <commonlib/helpers.h> |
| 7 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 8 | #include <device/mmio.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 9 | #include <delay.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <device/pci_ids.h> |
| 12 | #include <device/pci_ops.h> |
| 13 | #include <intelblocks/cse.h> |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 14 | #include <security/vboot/misc.h> |
| 15 | #include <security/vboot/vboot_common.h> |
Subrata Banik | 05e06cd | 2017-11-09 15:04:09 +0530 | [diff] [blame] | 16 | #include <soc/iomap.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 17 | #include <soc/pci_devs.h> |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 18 | #include <soc/me.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 19 | #include <string.h> |
| 20 | #include <timer.h> |
| 21 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 22 | #define MAX_HECI_MESSAGE_RETRY_COUNT 5 |
| 23 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 24 | /* Wait up to 15 sec for HECI to get ready */ |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 25 | #define HECI_DELAY_READY_MS (15 * 1000) |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 26 | /* Wait up to 100 usec between circular buffer polls */ |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 27 | #define HECI_DELAY_US 100 |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 28 | /* Wait up to 5 sec for CSE to chew something we sent */ |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 29 | #define HECI_SEND_TIMEOUT_MS (5 * 1000) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 30 | /* Wait up to 5 sec for CSE to blurp a reply */ |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 31 | #define HECI_READ_TIMEOUT_MS (5 * 1000) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 32 | /* Wait up to 1 ms for CSE CIP */ |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 33 | #define HECI_CIP_TIMEOUT_US 1000 |
Subrata Banik | f576581 | 2021-09-30 13:37:10 +0530 | [diff] [blame] | 34 | /* Wait up to 5 seconds for CSE to boot from RO(BP1) */ |
| 35 | #define CSE_DELAY_BOOT_TO_RO_MS (5 * 1000) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 36 | |
| 37 | #define SLOT_SIZE sizeof(uint32_t) |
| 38 | |
| 39 | #define MMIO_CSE_CB_WW 0x00 |
| 40 | #define MMIO_HOST_CSR 0x04 |
| 41 | #define MMIO_CSE_CB_RW 0x08 |
| 42 | #define MMIO_CSE_CSR 0x0c |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 43 | #define MMIO_CSE_DEVIDLE 0x800 |
| 44 | #define CSE_DEV_IDLE (1 << 2) |
| 45 | #define CSE_DEV_CIP (1 << 0) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 46 | |
| 47 | #define CSR_IE (1 << 0) |
| 48 | #define CSR_IS (1 << 1) |
| 49 | #define CSR_IG (1 << 2) |
| 50 | #define CSR_READY (1 << 3) |
| 51 | #define CSR_RESET (1 << 4) |
| 52 | #define CSR_RP_START 8 |
| 53 | #define CSR_RP (((1 << 8) - 1) << CSR_RP_START) |
| 54 | #define CSR_WP_START 16 |
| 55 | #define CSR_WP (((1 << 8) - 1) << CSR_WP_START) |
| 56 | #define CSR_CBD_START 24 |
| 57 | #define CSR_CBD (((1 << 8) - 1) << CSR_CBD_START) |
| 58 | |
| 59 | #define MEI_HDR_IS_COMPLETE (1 << 31) |
| 60 | #define MEI_HDR_LENGTH_START 16 |
| 61 | #define MEI_HDR_LENGTH_SIZE 9 |
| 62 | #define MEI_HDR_LENGTH (((1 << MEI_HDR_LENGTH_SIZE) - 1) \ |
| 63 | << MEI_HDR_LENGTH_START) |
| 64 | #define MEI_HDR_HOST_ADDR_START 8 |
| 65 | #define MEI_HDR_HOST_ADDR (((1 << 8) - 1) << MEI_HDR_HOST_ADDR_START) |
| 66 | #define MEI_HDR_CSE_ADDR_START 0 |
| 67 | #define MEI_HDR_CSE_ADDR (((1 << 8) - 1) << MEI_HDR_CSE_ADDR_START) |
| 68 | |
Subrata Banik | 38abbda | 2021-09-30 13:15:50 +0530 | [diff] [blame] | 69 | /* Get HECI BAR 0 from PCI configuration space */ |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 70 | static uintptr_t get_cse_bar(pci_devfn_t dev) |
Subrata Banik | 38abbda | 2021-09-30 13:15:50 +0530 | [diff] [blame] | 71 | { |
| 72 | uintptr_t bar; |
| 73 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 74 | bar = pci_read_config32(dev, PCI_BASE_ADDRESS_0); |
Subrata Banik | 38abbda | 2021-09-30 13:15:50 +0530 | [diff] [blame] | 75 | assert(bar != 0); |
| 76 | /* |
| 77 | * Bits 31-12 are the base address as per EDS for SPI, |
| 78 | * Don't care about 0-11 bit |
| 79 | */ |
| 80 | return bar & ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 81 | } |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Initialize the device with provided temporary BAR. If BAR is 0 use a |
| 85 | * default. This is intended for pre-mem usage only where BARs haven't been |
| 86 | * assigned yet and devices are not enabled. |
| 87 | */ |
| 88 | void heci_init(uintptr_t tempbar) |
| 89 | { |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 90 | pci_devfn_t dev = PCH_DEV_CSE; |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 91 | |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 92 | u16 pcireg; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 93 | |
| 94 | /* Assume it is already initialized, nothing else to do */ |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 95 | if (get_cse_bar(dev)) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 96 | return; |
| 97 | |
| 98 | /* Use default pre-ram bar */ |
| 99 | if (!tempbar) |
| 100 | tempbar = HECI1_BASE_ADDRESS; |
| 101 | |
| 102 | /* Assign Resources to HECI1 */ |
| 103 | /* Clear BIT 1-2 of Command Register */ |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 104 | pcireg = pci_read_config16(dev, PCI_COMMAND); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 105 | pcireg &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 106 | pci_write_config16(dev, PCI_COMMAND, pcireg); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 107 | |
| 108 | /* Program Temporary BAR for HECI1 */ |
| 109 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, tempbar); |
| 110 | pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0x0); |
| 111 | |
| 112 | /* Enable Bus Master and MMIO Space */ |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 113 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
Sridhar Siricilla | cb2fd20 | 2021-06-09 19:27:06 +0530 | [diff] [blame] | 114 | |
| 115 | /* Trigger HECI Reset and make Host ready for communication with CSE */ |
| 116 | heci_reset(); |
Subrata Banik | 05e06cd | 2017-11-09 15:04:09 +0530 | [diff] [blame] | 117 | } |
| 118 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 119 | static uint32_t read_bar(pci_devfn_t dev, uint32_t offset) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 120 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 121 | return read32p(get_cse_bar(dev) + offset); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 124 | static void write_bar(pci_devfn_t dev, uint32_t offset, uint32_t val) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 125 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 126 | return write32p(get_cse_bar(dev) + offset, val); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static uint32_t read_cse_csr(void) |
| 130 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 131 | return read_bar(PCH_DEV_CSE, MMIO_CSE_CSR); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static uint32_t read_host_csr(void) |
| 135 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 136 | return read_bar(PCH_DEV_CSE, MMIO_HOST_CSR); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static void write_host_csr(uint32_t data) |
| 140 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 141 | write_bar(PCH_DEV_CSE, MMIO_HOST_CSR, data); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static size_t filled_slots(uint32_t data) |
| 145 | { |
| 146 | uint8_t wp, rp; |
| 147 | rp = data >> CSR_RP_START; |
| 148 | wp = data >> CSR_WP_START; |
| 149 | return (uint8_t) (wp - rp); |
| 150 | } |
| 151 | |
| 152 | static size_t cse_filled_slots(void) |
| 153 | { |
| 154 | return filled_slots(read_cse_csr()); |
| 155 | } |
| 156 | |
| 157 | static size_t host_empty_slots(void) |
| 158 | { |
| 159 | uint32_t csr; |
| 160 | csr = read_host_csr(); |
| 161 | |
| 162 | return ((csr & CSR_CBD) >> CSR_CBD_START) - filled_slots(csr); |
| 163 | } |
| 164 | |
| 165 | static void clear_int(void) |
| 166 | { |
| 167 | uint32_t csr; |
| 168 | csr = read_host_csr(); |
| 169 | csr |= CSR_IS; |
| 170 | write_host_csr(csr); |
| 171 | } |
| 172 | |
| 173 | static uint32_t read_slot(void) |
| 174 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 175 | return read_bar(PCH_DEV_CSE, MMIO_CSE_CB_RW); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void write_slot(uint32_t val) |
| 179 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 180 | write_bar(PCH_DEV_CSE, MMIO_CSE_CB_WW, val); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static int wait_write_slots(size_t cnt) |
| 184 | { |
| 185 | struct stopwatch sw; |
| 186 | |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 187 | stopwatch_init_msecs_expire(&sw, HECI_SEND_TIMEOUT_MS); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 188 | while (host_empty_slots() < cnt) { |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 189 | udelay(HECI_DELAY_US); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 190 | if (stopwatch_expired(&sw)) { |
| 191 | printk(BIOS_ERR, "HECI: timeout, buffer not drained\n"); |
| 192 | return 0; |
| 193 | } |
| 194 | } |
| 195 | return 1; |
| 196 | } |
| 197 | |
| 198 | static int wait_read_slots(size_t cnt) |
| 199 | { |
| 200 | struct stopwatch sw; |
| 201 | |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 202 | stopwatch_init_msecs_expire(&sw, HECI_READ_TIMEOUT_MS); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 203 | while (cse_filled_slots() < cnt) { |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 204 | udelay(HECI_DELAY_US); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 205 | if (stopwatch_expired(&sw)) { |
| 206 | printk(BIOS_ERR, "HECI: timed out reading answer!\n"); |
| 207 | return 0; |
| 208 | } |
| 209 | } |
| 210 | return 1; |
| 211 | } |
| 212 | |
| 213 | /* get number of full 4-byte slots */ |
| 214 | static size_t bytes_to_slots(size_t bytes) |
| 215 | { |
| 216 | return ALIGN_UP(bytes, SLOT_SIZE) / SLOT_SIZE; |
| 217 | } |
| 218 | |
| 219 | static int cse_ready(void) |
| 220 | { |
| 221 | uint32_t csr; |
| 222 | csr = read_cse_csr(); |
| 223 | return csr & CSR_READY; |
| 224 | } |
| 225 | |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 226 | static bool cse_check_hfs1_com(int mode) |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 227 | { |
| 228 | union me_hfsts1 hfs1; |
| 229 | hfs1.data = me_read_config32(PCI_ME_HFSTS1); |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 230 | return hfs1.fields.operation_mode == mode; |
| 231 | } |
| 232 | |
| 233 | bool cse_is_hfs1_cws_normal(void) |
| 234 | { |
| 235 | union me_hfsts1 hfs1; |
| 236 | hfs1.data = me_read_config32(PCI_ME_HFSTS1); |
| 237 | if (hfs1.fields.working_state == ME_HFS1_CWS_NORMAL) |
| 238 | return true; |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | bool cse_is_hfs1_com_normal(void) |
| 243 | { |
| 244 | return cse_check_hfs1_com(ME_HFS1_COM_NORMAL); |
| 245 | } |
| 246 | |
| 247 | bool cse_is_hfs1_com_secover_mei_msg(void) |
| 248 | { |
| 249 | return cse_check_hfs1_com(ME_HFS1_COM_SECOVER_MEI_MSG); |
| 250 | } |
| 251 | |
| 252 | bool cse_is_hfs1_com_soft_temp_disable(void) |
| 253 | { |
| 254 | return cse_check_hfs1_com(ME_HFS1_COM_SOFT_TEMP_DISABLE); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 255 | } |
| 256 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 257 | bool cse_is_hfs3_fw_sku_lite(void) |
Sridhar Siricilla | 3465d27 | 2020-02-06 15:31:04 +0530 | [diff] [blame] | 258 | { |
| 259 | union me_hfsts3 hfs3; |
| 260 | hfs3.data = me_read_config32(PCI_ME_HFSTS3); |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 261 | return hfs3.fields.fw_sku == ME_HFS3_FW_SKU_LITE; |
Sridhar Siricilla | 3465d27 | 2020-02-06 15:31:04 +0530 | [diff] [blame] | 262 | } |
| 263 | |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 264 | /* Makes the host ready to communicate with CSE */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 265 | void cse_set_host_ready(void) |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 266 | { |
| 267 | uint32_t csr; |
| 268 | csr = read_host_csr(); |
| 269 | csr &= ~CSR_RESET; |
| 270 | csr |= (CSR_IG | CSR_READY); |
| 271 | write_host_csr(csr); |
| 272 | } |
| 273 | |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 274 | /* Polls for ME mode ME_HFS1_COM_SECOVER_MEI_MSG for 15 seconds */ |
| 275 | uint8_t cse_wait_sec_override_mode(void) |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 276 | { |
| 277 | struct stopwatch sw; |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 278 | stopwatch_init_msecs_expire(&sw, HECI_DELAY_READY_MS); |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 279 | while (!cse_is_hfs1_com_secover_mei_msg()) { |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 280 | udelay(HECI_DELAY_US); |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 281 | if (stopwatch_expired(&sw)) { |
| 282 | printk(BIOS_ERR, "HECI: Timed out waiting for SEC_OVERRIDE mode!\n"); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 283 | return 0; |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 284 | } |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 285 | } |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 286 | printk(BIOS_DEBUG, "HECI: CSE took %lu ms to enter security override mode\n", |
| 287 | stopwatch_duration_msecs(&sw)); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 288 | return 1; |
| 289 | } |
| 290 | |
Sridhar Siricilla | 09ea371 | 2019-11-12 23:35:50 +0530 | [diff] [blame] | 291 | /* |
| 292 | * Polls for CSE's current operation mode 'Soft Temporary Disable'. |
| 293 | * The CSE enters the current operation mode when it boots from RO(BP1). |
| 294 | */ |
| 295 | uint8_t cse_wait_com_soft_temp_disable(void) |
| 296 | { |
| 297 | struct stopwatch sw; |
Subrata Banik | f576581 | 2021-09-30 13:37:10 +0530 | [diff] [blame] | 298 | stopwatch_init_msecs_expire(&sw, CSE_DELAY_BOOT_TO_RO_MS); |
Sridhar Siricilla | 09ea371 | 2019-11-12 23:35:50 +0530 | [diff] [blame] | 299 | while (!cse_is_hfs1_com_soft_temp_disable()) { |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 300 | udelay(HECI_DELAY_US); |
Sridhar Siricilla | 09ea371 | 2019-11-12 23:35:50 +0530 | [diff] [blame] | 301 | if (stopwatch_expired(&sw)) { |
| 302 | printk(BIOS_ERR, "HECI: Timed out waiting for CSE to boot from RO!\n"); |
| 303 | return 0; |
| 304 | } |
| 305 | } |
| 306 | printk(BIOS_SPEW, "HECI: CSE took %lu ms to boot from RO\n", |
| 307 | stopwatch_duration_msecs(&sw)); |
| 308 | return 1; |
| 309 | } |
| 310 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 311 | static int wait_heci_ready(void) |
| 312 | { |
| 313 | struct stopwatch sw; |
| 314 | |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 315 | stopwatch_init_msecs_expire(&sw, HECI_DELAY_READY_MS); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 316 | while (!cse_ready()) { |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 317 | udelay(HECI_DELAY_US); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 318 | if (stopwatch_expired(&sw)) |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | return 1; |
| 323 | } |
| 324 | |
| 325 | static void host_gen_interrupt(void) |
| 326 | { |
| 327 | uint32_t csr; |
| 328 | csr = read_host_csr(); |
| 329 | csr |= CSR_IG; |
| 330 | write_host_csr(csr); |
| 331 | } |
| 332 | |
| 333 | static size_t hdr_get_length(uint32_t hdr) |
| 334 | { |
| 335 | return (hdr & MEI_HDR_LENGTH) >> MEI_HDR_LENGTH_START; |
| 336 | } |
| 337 | |
| 338 | static int |
| 339 | send_one_message(uint32_t hdr, const void *buff) |
| 340 | { |
| 341 | size_t pend_len, pend_slots, remainder, i; |
| 342 | uint32_t tmp; |
| 343 | const uint32_t *p = buff; |
| 344 | |
| 345 | /* Get space for the header */ |
| 346 | if (!wait_write_slots(1)) |
| 347 | return 0; |
| 348 | |
| 349 | /* First, write header */ |
| 350 | write_slot(hdr); |
| 351 | |
| 352 | pend_len = hdr_get_length(hdr); |
| 353 | pend_slots = bytes_to_slots(pend_len); |
| 354 | |
| 355 | if (!wait_write_slots(pend_slots)) |
| 356 | return 0; |
| 357 | |
| 358 | /* Write the body in whole slots */ |
| 359 | i = 0; |
| 360 | while (i < ALIGN_DOWN(pend_len, SLOT_SIZE)) { |
| 361 | write_slot(*p++); |
| 362 | i += SLOT_SIZE; |
| 363 | } |
| 364 | |
| 365 | remainder = pend_len % SLOT_SIZE; |
| 366 | /* Pad to 4 bytes not touching caller's buffer */ |
| 367 | if (remainder) { |
| 368 | memcpy(&tmp, p, remainder); |
| 369 | write_slot(tmp); |
| 370 | } |
| 371 | |
| 372 | host_gen_interrupt(); |
| 373 | |
| 374 | /* Make sure nothing bad happened during transmission */ |
| 375 | if (!cse_ready()) |
| 376 | return 0; |
| 377 | |
| 378 | return pend_len; |
| 379 | } |
| 380 | |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 381 | /* |
| 382 | * Send message msg of size len to host from host_addr to cse_addr. |
| 383 | * Returns 1 on success and 0 otherwise. |
| 384 | * In case of error heci_reset() may be required. |
| 385 | */ |
| 386 | static int |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 387 | heci_send(const void *msg, size_t len, uint8_t host_addr, uint8_t client_addr) |
| 388 | { |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 389 | uint8_t retry; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 390 | uint32_t csr, hdr; |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 391 | size_t sent, remaining, cb_size, max_length; |
| 392 | const uint8_t *p; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 393 | |
| 394 | if (!msg || !len) |
| 395 | return 0; |
| 396 | |
| 397 | clear_int(); |
| 398 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 399 | for (retry = 0; retry < MAX_HECI_MESSAGE_RETRY_COUNT; retry++) { |
| 400 | p = msg; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 401 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 402 | if (!wait_heci_ready()) { |
| 403 | printk(BIOS_ERR, "HECI: not ready\n"); |
| 404 | continue; |
| 405 | } |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 406 | |
Subrata Banik | 4a722f5 | 2017-11-13 14:56:42 +0530 | [diff] [blame] | 407 | csr = read_host_csr(); |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 408 | cb_size = ((csr & CSR_CBD) >> CSR_CBD_START) * SLOT_SIZE; |
| 409 | /* |
| 410 | * Reserve one slot for the header. Limit max message |
| 411 | * length by 9 bits that are available in the header. |
| 412 | */ |
| 413 | max_length = MIN(cb_size, (1 << MEI_HDR_LENGTH_SIZE) - 1) |
| 414 | - SLOT_SIZE; |
| 415 | remaining = len; |
| 416 | |
| 417 | /* |
| 418 | * Fragment the message into smaller messages not exceeding |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 419 | * useful circular buffer length. Mark last message complete. |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 420 | */ |
| 421 | do { |
| 422 | hdr = MIN(max_length, remaining) |
| 423 | << MEI_HDR_LENGTH_START; |
| 424 | hdr |= client_addr << MEI_HDR_CSE_ADDR_START; |
| 425 | hdr |= host_addr << MEI_HDR_HOST_ADDR_START; |
| 426 | hdr |= (MIN(max_length, remaining) == remaining) ? |
Lee Leahy | 68ab0b5 | 2017-03-10 13:42:34 -0800 | [diff] [blame] | 427 | MEI_HDR_IS_COMPLETE : 0; |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 428 | sent = send_one_message(hdr, p); |
| 429 | p += sent; |
| 430 | remaining -= sent; |
| 431 | } while (remaining > 0 && sent != 0); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 432 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 433 | if (!remaining) |
| 434 | return 1; |
| 435 | } |
| 436 | return 0; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static size_t |
| 440 | recv_one_message(uint32_t *hdr, void *buff, size_t maxlen) |
| 441 | { |
| 442 | uint32_t reg, *p = buff; |
| 443 | size_t recv_slots, recv_len, remainder, i; |
| 444 | |
| 445 | /* first get the header */ |
| 446 | if (!wait_read_slots(1)) |
| 447 | return 0; |
| 448 | |
| 449 | *hdr = read_slot(); |
| 450 | recv_len = hdr_get_length(*hdr); |
| 451 | |
| 452 | if (!recv_len) |
| 453 | printk(BIOS_WARNING, "HECI: message is zero-sized\n"); |
| 454 | |
| 455 | recv_slots = bytes_to_slots(recv_len); |
| 456 | |
| 457 | i = 0; |
| 458 | if (recv_len > maxlen) { |
| 459 | printk(BIOS_ERR, "HECI: response is too big\n"); |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | /* wait for the rest of messages to arrive */ |
| 464 | wait_read_slots(recv_slots); |
| 465 | |
| 466 | /* fetch whole slots first */ |
| 467 | while (i < ALIGN_DOWN(recv_len, SLOT_SIZE)) { |
| 468 | *p++ = read_slot(); |
| 469 | i += SLOT_SIZE; |
| 470 | } |
| 471 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 472 | /* |
| 473 | * If ME is not ready, something went wrong and |
| 474 | * we received junk |
| 475 | */ |
| 476 | if (!cse_ready()) |
| 477 | return 0; |
| 478 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 479 | remainder = recv_len % SLOT_SIZE; |
| 480 | |
| 481 | if (remainder) { |
| 482 | reg = read_slot(); |
| 483 | memcpy(p, ®, remainder); |
| 484 | } |
| 485 | |
| 486 | return recv_len; |
| 487 | } |
| 488 | |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 489 | /* |
| 490 | * Receive message into buff not exceeding maxlen. Message is considered |
| 491 | * successfully received if a 'complete' indication is read from ME side |
| 492 | * and there was enough space in the buffer to fit that message. maxlen |
| 493 | * is updated with size of message that was received. Returns 0 on failure |
| 494 | * and 1 on success. |
| 495 | * In case of error heci_reset() may be required. |
| 496 | */ |
| 497 | static int heci_receive(void *buff, size_t *maxlen) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 498 | { |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 499 | uint8_t retry; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 500 | size_t left, received; |
| 501 | uint32_t hdr = 0; |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 502 | uint8_t *p; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 503 | |
| 504 | if (!buff || !maxlen || !*maxlen) |
| 505 | return 0; |
| 506 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 507 | clear_int(); |
| 508 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 509 | for (retry = 0; retry < MAX_HECI_MESSAGE_RETRY_COUNT; retry++) { |
| 510 | p = buff; |
| 511 | left = *maxlen; |
| 512 | |
| 513 | if (!wait_heci_ready()) { |
| 514 | printk(BIOS_ERR, "HECI: not ready\n"); |
| 515 | continue; |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * Receive multiple packets until we meet one marked |
| 520 | * complete or we run out of space in caller-provided buffer. |
| 521 | */ |
| 522 | do { |
| 523 | received = recv_one_message(&hdr, p, left); |
Lijian Zhao | c50296d | 2017-12-15 19:10:18 -0800 | [diff] [blame] | 524 | if (!received) { |
Elyes HAOUAS | 3d45000 | 2018-08-09 18:55:58 +0200 | [diff] [blame] | 525 | printk(BIOS_ERR, "HECI: Failed to receive!\n"); |
Lijian Zhao | c50296d | 2017-12-15 19:10:18 -0800 | [diff] [blame] | 526 | return 0; |
| 527 | } |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 528 | left -= received; |
| 529 | p += received; |
| 530 | /* If we read out everything ping to send more */ |
| 531 | if (!(hdr & MEI_HDR_IS_COMPLETE) && !cse_filled_slots()) |
| 532 | host_gen_interrupt(); |
| 533 | } while (received && !(hdr & MEI_HDR_IS_COMPLETE) && left > 0); |
| 534 | |
| 535 | if ((hdr & MEI_HDR_IS_COMPLETE) && received) { |
| 536 | *maxlen = p - (uint8_t *) buff; |
| 537 | return 1; |
| 538 | } |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 539 | } |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 540 | return 0; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 541 | } |
| 542 | |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 543 | int heci_send_receive(const void *snd_msg, size_t snd_sz, void *rcv_msg, size_t *rcv_sz, |
| 544 | uint8_t cse_addr) |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 545 | { |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 546 | if (!heci_send(snd_msg, snd_sz, BIOS_HOST_ADDR, cse_addr)) { |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 547 | printk(BIOS_ERR, "HECI: send Failed\n"); |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | if (rcv_msg != NULL) { |
| 552 | if (!heci_receive(rcv_msg, rcv_sz)) { |
| 553 | printk(BIOS_ERR, "HECI: receive Failed\n"); |
| 554 | return 0; |
| 555 | } |
| 556 | } |
| 557 | return 1; |
| 558 | } |
| 559 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 560 | /* |
| 561 | * Attempt to reset the device. This is useful when host and ME are out |
| 562 | * of sync during transmission or ME didn't understand the message. |
| 563 | */ |
| 564 | int heci_reset(void) |
| 565 | { |
| 566 | uint32_t csr; |
| 567 | |
Duncan Laurie | 15ca903 | 2020-11-05 10:09:07 -0800 | [diff] [blame] | 568 | /* Clear post code to prevent eventlog entry from unknown code. */ |
| 569 | post_code(0); |
| 570 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 571 | /* Send reset request */ |
| 572 | csr = read_host_csr(); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 573 | csr |= (CSR_RESET | CSR_IG); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 574 | write_host_csr(csr); |
| 575 | |
| 576 | if (wait_heci_ready()) { |
| 577 | /* Device is back on its imaginary feet, clear reset */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 578 | cse_set_host_ready(); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 579 | return 1; |
| 580 | } |
| 581 | |
| 582 | printk(BIOS_CRIT, "HECI: reset failed\n"); |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
Subrata Banik | 3710e99 | 2021-09-30 16:59:09 +0530 | [diff] [blame] | 587 | bool is_cse_devfn_visible(unsigned int devfn) |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 588 | { |
Subrata Banik | 3710e99 | 2021-09-30 16:59:09 +0530 | [diff] [blame] | 589 | int slot = PCI_SLOT(devfn); |
| 590 | int func = PCI_FUNC(devfn); |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 591 | |
Subrata Banik | 3710e99 | 2021-09-30 16:59:09 +0530 | [diff] [blame] | 592 | if (!is_devfn_enabled(devfn)) { |
| 593 | printk(BIOS_WARNING, "HECI: CSE device %02x.%01x is disabled\n", slot, func); |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 594 | return false; |
| 595 | } |
| 596 | |
Subrata Banik | 3710e99 | 2021-09-30 16:59:09 +0530 | [diff] [blame] | 597 | if (pci_read_config16(PCI_DEV(0, slot, func), PCI_VENDOR_ID) == 0xFFFF) { |
| 598 | printk(BIOS_WARNING, "HECI: CSE device %02x.%01x is hidden\n", slot, func); |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 599 | return false; |
| 600 | } |
| 601 | |
| 602 | return true; |
| 603 | } |
| 604 | |
Subrata Banik | 3710e99 | 2021-09-30 16:59:09 +0530 | [diff] [blame] | 605 | bool is_cse_enabled(void) |
| 606 | { |
| 607 | return is_cse_devfn_visible(PCH_DEVFN_CSE); |
| 608 | } |
| 609 | |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 610 | uint32_t me_read_config32(int offset) |
| 611 | { |
| 612 | return pci_read_config32(PCH_DEV_CSE, offset); |
| 613 | } |
| 614 | |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 615 | static bool cse_is_global_reset_allowed(void) |
| 616 | { |
| 617 | /* |
| 618 | * Allow sending GLOBAL_RESET command only if: |
| 619 | * - CSE's current working state is Normal and current operation mode is Normal. |
| 620 | * - (or) CSE's current working state is normal and current operation mode can |
| 621 | * be Soft Temp Disable or Security Override Mode if CSE's Firmware SKU is |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 622 | * Lite. |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 623 | */ |
| 624 | if (!cse_is_hfs1_cws_normal()) |
| 625 | return false; |
| 626 | |
| 627 | if (cse_is_hfs1_com_normal()) |
| 628 | return true; |
| 629 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 630 | if (cse_is_hfs3_fw_sku_lite()) { |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 631 | if (cse_is_hfs1_com_soft_temp_disable() || cse_is_hfs1_com_secover_mei_msg()) |
| 632 | return true; |
| 633 | } |
| 634 | return false; |
| 635 | } |
| 636 | |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 637 | /* |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 638 | * Sends GLOBAL_RESET_REQ cmd to CSE with reset type GLOBAL_RESET. |
| 639 | * Returns 0 on failure and 1 on success. |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 640 | */ |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 641 | static int cse_request_reset(enum rst_req_type rst_type) |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 642 | { |
| 643 | int status; |
| 644 | struct mkhi_hdr reply; |
| 645 | struct reset_message { |
| 646 | struct mkhi_hdr hdr; |
| 647 | uint8_t req_origin; |
| 648 | uint8_t reset_type; |
| 649 | } __packed; |
| 650 | struct reset_message msg = { |
| 651 | .hdr = { |
| 652 | .group_id = MKHI_GROUP_ID_CBM, |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 653 | .command = MKHI_CBM_GLOBAL_RESET_REQ, |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 654 | }, |
| 655 | .req_origin = GR_ORIGIN_BIOS_POST, |
| 656 | .reset_type = rst_type |
| 657 | }; |
| 658 | size_t reply_size; |
| 659 | |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 660 | printk(BIOS_DEBUG, "HECI: Global Reset(Type:%d) Command\n", rst_type); |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 661 | |
Sridhar Siricilla | c2a2d2b | 2020-02-27 17:16:13 +0530 | [diff] [blame] | 662 | if (!(rst_type == GLOBAL_RESET || rst_type == CSE_RESET_ONLY)) { |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 663 | printk(BIOS_ERR, "HECI: Unsupported reset type is requested\n"); |
| 664 | return 0; |
| 665 | } |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 666 | |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 667 | if (!cse_is_global_reset_allowed() || !is_cse_enabled()) { |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 668 | printk(BIOS_ERR, "HECI: CSE does not meet required prerequisites\n"); |
| 669 | return 0; |
| 670 | } |
| 671 | |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 672 | heci_reset(); |
| 673 | |
| 674 | reply_size = sizeof(reply); |
| 675 | memset(&reply, 0, reply_size); |
| 676 | |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 677 | if (rst_type == CSE_RESET_ONLY) |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 678 | status = heci_send(&msg, sizeof(msg), BIOS_HOST_ADDR, HECI_MKHI_ADDR); |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 679 | else |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 680 | status = heci_send_receive(&msg, sizeof(msg), &reply, &reply_size, |
| 681 | HECI_MKHI_ADDR); |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 682 | |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 683 | printk(BIOS_DEBUG, "HECI: Global Reset %s!\n", status ? "success" : "failure"); |
| 684 | return status; |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 685 | } |
| 686 | |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 687 | int cse_request_global_reset(void) |
| 688 | { |
| 689 | return cse_request_reset(GLOBAL_RESET); |
| 690 | } |
| 691 | |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 692 | static bool cse_is_hmrfpo_enable_allowed(void) |
| 693 | { |
| 694 | /* |
| 695 | * Allow sending HMRFPO ENABLE command only if: |
| 696 | * - CSE's current working state is Normal and current operation mode is Normal |
| 697 | * - (or) cse's current working state is normal and current operation mode is |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 698 | * Soft Temp Disable if CSE's Firmware SKU is Lite |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 699 | */ |
| 700 | if (!cse_is_hfs1_cws_normal()) |
| 701 | return false; |
| 702 | |
| 703 | if (cse_is_hfs1_com_normal()) |
| 704 | return true; |
| 705 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 706 | if (cse_is_hfs3_fw_sku_lite() && cse_is_hfs1_com_soft_temp_disable()) |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 707 | return true; |
| 708 | |
| 709 | return false; |
| 710 | } |
| 711 | |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 712 | /* Sends HMRFPO Enable command to CSE */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 713 | int cse_hmrfpo_enable(void) |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 714 | { |
| 715 | struct hmrfpo_enable_msg { |
| 716 | struct mkhi_hdr hdr; |
| 717 | uint32_t nonce[2]; |
| 718 | } __packed; |
| 719 | |
| 720 | /* HMRFPO Enable message */ |
| 721 | struct hmrfpo_enable_msg msg = { |
| 722 | .hdr = { |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 723 | .group_id = MKHI_GROUP_ID_HMRFPO, |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 724 | .command = MKHI_HMRFPO_ENABLE, |
| 725 | }, |
| 726 | .nonce = {0}, |
| 727 | }; |
| 728 | |
| 729 | /* HMRFPO Enable response */ |
| 730 | struct hmrfpo_enable_resp { |
| 731 | struct mkhi_hdr hdr; |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 732 | /* Base addr for factory data area, not relevant for client SKUs */ |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 733 | uint32_t fct_base; |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 734 | /* Length of factory data area, not relevant for client SKUs */ |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 735 | uint32_t fct_limit; |
| 736 | uint8_t status; |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 737 | uint8_t reserved[3]; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 738 | } __packed; |
| 739 | |
| 740 | struct hmrfpo_enable_resp resp; |
| 741 | size_t resp_size = sizeof(struct hmrfpo_enable_resp); |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 742 | |
| 743 | printk(BIOS_DEBUG, "HECI: Send HMRFPO Enable Command\n"); |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 744 | |
| 745 | if (!cse_is_hmrfpo_enable_allowed()) { |
| 746 | printk(BIOS_ERR, "HECI: CSE does not meet required prerequisites\n"); |
| 747 | return 0; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | if (!heci_send_receive(&msg, sizeof(struct hmrfpo_enable_msg), |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 751 | &resp, &resp_size, HECI_MKHI_ADDR)) |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 752 | return 0; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 753 | |
| 754 | if (resp.hdr.result) { |
| 755 | printk(BIOS_ERR, "HECI: Resp Failed:%d\n", resp.hdr.result); |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 756 | return 0; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 757 | } |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 758 | |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 759 | if (resp.status) { |
| 760 | printk(BIOS_ERR, "HECI: HMRFPO_Enable Failed (resp status: %d)\n", resp.status); |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | return 1; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /* |
| 768 | * Sends HMRFPO Get Status command to CSE to get the HMRFPO status. |
Sridhar Siricilla | 63be918 | 2020-01-19 12:38:56 +0530 | [diff] [blame] | 769 | * The status can be DISABLED/LOCKED/ENABLED |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 770 | */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 771 | int cse_hmrfpo_get_status(void) |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 772 | { |
| 773 | struct hmrfpo_get_status_msg { |
| 774 | struct mkhi_hdr hdr; |
| 775 | } __packed; |
| 776 | |
| 777 | struct hmrfpo_get_status_resp { |
| 778 | struct mkhi_hdr hdr; |
| 779 | uint8_t status; |
Sridhar Siricilla | 63be918 | 2020-01-19 12:38:56 +0530 | [diff] [blame] | 780 | uint8_t reserved[3]; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 781 | } __packed; |
| 782 | |
| 783 | struct hmrfpo_get_status_msg msg = { |
| 784 | .hdr = { |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 785 | .group_id = MKHI_GROUP_ID_HMRFPO, |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 786 | .command = MKHI_HMRFPO_GET_STATUS, |
| 787 | }, |
| 788 | }; |
| 789 | struct hmrfpo_get_status_resp resp; |
| 790 | size_t resp_size = sizeof(struct hmrfpo_get_status_resp); |
| 791 | |
| 792 | printk(BIOS_INFO, "HECI: Sending Get HMRFPO Status Command\n"); |
| 793 | |
Sridhar Siricilla | 206905c | 2020-02-06 18:48:22 +0530 | [diff] [blame] | 794 | if (!cse_is_hfs1_cws_normal()) { |
| 795 | printk(BIOS_ERR, "HECI: CSE's current working state is not Normal\n"); |
| 796 | return -1; |
| 797 | } |
| 798 | |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 799 | if (!heci_send_receive(&msg, sizeof(struct hmrfpo_get_status_msg), |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 800 | &resp, &resp_size, HECI_MKHI_ADDR)) { |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 801 | printk(BIOS_ERR, "HECI: HMRFPO send/receive fail\n"); |
| 802 | return -1; |
| 803 | } |
| 804 | |
| 805 | if (resp.hdr.result) { |
| 806 | printk(BIOS_ERR, "HECI: HMRFPO Resp Failed:%d\n", |
| 807 | resp.hdr.result); |
| 808 | return -1; |
| 809 | } |
| 810 | |
| 811 | return resp.status; |
| 812 | } |
| 813 | |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 814 | void print_me_fw_version(void *unused) |
| 815 | { |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 816 | struct me_fw_ver_resp resp = {0}; |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 817 | |
| 818 | /* Ignore if UART debugging is disabled */ |
| 819 | if (!CONFIG(CONSOLE_SERIAL)) |
| 820 | return; |
| 821 | |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 822 | if (get_me_fw_version(&resp) == CB_SUCCESS) { |
| 823 | printk(BIOS_DEBUG, "ME: Version: %d.%d.%d.%d\n", resp.code.major, |
| 824 | resp.code.minor, resp.code.hotfix, resp.code.build); |
| 825 | return; |
| 826 | } |
| 827 | printk(BIOS_DEBUG, "ME: Version: Unavailable\n"); |
| 828 | } |
| 829 | |
| 830 | enum cb_err get_me_fw_version(struct me_fw_ver_resp *resp) |
| 831 | { |
| 832 | const struct mkhi_hdr fw_ver_msg = { |
| 833 | .group_id = MKHI_GROUP_ID_GEN, |
| 834 | .command = MKHI_GEN_GET_FW_VERSION, |
| 835 | }; |
| 836 | |
| 837 | if (resp == NULL) { |
| 838 | printk(BIOS_ERR, "%s failed, null pointer parameter\n", __func__); |
| 839 | return CB_ERR; |
| 840 | } |
| 841 | size_t resp_size = sizeof(*resp); |
| 842 | |
Wim Vervoorn | 8602fb7 | 2020-03-30 12:17:54 +0200 | [diff] [blame] | 843 | /* Ignore if CSE is disabled */ |
| 844 | if (!is_cse_enabled()) |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 845 | return CB_ERR; |
Wim Vervoorn | 8602fb7 | 2020-03-30 12:17:54 +0200 | [diff] [blame] | 846 | |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 847 | /* |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 848 | * Ignore if ME Firmware SKU type is Lite since |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 849 | * print_boot_partition_info() logs RO(BP1) and RW(BP2) versions. |
| 850 | */ |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 851 | if (cse_is_hfs3_fw_sku_lite()) |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 852 | return CB_ERR; |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 853 | |
| 854 | /* |
| 855 | * Prerequisites: |
| 856 | * 1) HFSTS1 Current Working State is Normal |
| 857 | * 2) HFSTS1 Current Operation Mode is Normal |
| 858 | * 3) It's after DRAM INIT DONE message (taken care of by calling it |
| 859 | * during ramstage |
| 860 | */ |
| 861 | if (!cse_is_hfs1_cws_normal() || !cse_is_hfs1_com_normal()) |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 862 | return CB_ERR; |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 863 | |
| 864 | heci_reset(); |
| 865 | |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 866 | if (!heci_send_receive(&fw_ver_msg, sizeof(fw_ver_msg), resp, &resp_size, |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 867 | HECI_MKHI_ADDR)) |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 868 | return CB_ERR; |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 869 | |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 870 | if (resp->hdr.result) |
| 871 | return CB_ERR; |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 872 | |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 873 | |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 874 | return CB_SUCCESS; |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 875 | } |
| 876 | |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 877 | void cse_trigger_vboot_recovery(enum csme_failure_reason reason) |
| 878 | { |
| 879 | printk(BIOS_DEBUG, "cse: CSE status registers: HFSTS1: 0x%x, HFSTS2: 0x%x " |
| 880 | "HFSTS3: 0x%x\n", me_read_config32(PCI_ME_HFSTS1), |
| 881 | me_read_config32(PCI_ME_HFSTS2), me_read_config32(PCI_ME_HFSTS3)); |
| 882 | |
| 883 | if (CONFIG(VBOOT)) { |
| 884 | struct vb2_context *ctx = vboot_get_context(); |
| 885 | if (ctx == NULL) |
| 886 | goto failure; |
| 887 | vb2api_fail(ctx, VB2_RECOVERY_INTEL_CSE_LITE_SKU, reason); |
| 888 | vboot_save_data(ctx); |
| 889 | vboot_reboot(); |
| 890 | } |
| 891 | failure: |
| 892 | die("cse: Failed to trigger recovery mode(recovery subcode:%d)\n", reason); |
| 893 | } |
| 894 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 895 | static bool disable_cse_idle(pci_devfn_t dev) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 896 | { |
| 897 | struct stopwatch sw; |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 898 | uint32_t dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 899 | dev_idle_ctrl &= ~CSE_DEV_IDLE; |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 900 | write_bar(dev, MMIO_CSE_DEVIDLE, dev_idle_ctrl); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 901 | |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 902 | stopwatch_init_usecs_expire(&sw, HECI_CIP_TIMEOUT_US); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 903 | do { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 904 | dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 905 | if ((dev_idle_ctrl & CSE_DEV_CIP) == CSE_DEV_CIP) |
| 906 | return true; |
Subrata Banik | 03aef28 | 2021-09-28 18:10:24 +0530 | [diff] [blame] | 907 | udelay(HECI_DELAY_US); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 908 | } while (!stopwatch_expired(&sw)); |
| 909 | |
| 910 | return false; |
| 911 | } |
| 912 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 913 | static void enable_cse_idle(pci_devfn_t dev) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 914 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 915 | uint32_t dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 916 | dev_idle_ctrl |= CSE_DEV_IDLE; |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 917 | write_bar(dev, MMIO_CSE_DEVIDLE, dev_idle_ctrl); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 918 | } |
| 919 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 920 | enum cse_device_state get_cse_device_state(unsigned int devfn) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 921 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 922 | pci_devfn_t dev = PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn)); |
| 923 | uint32_t dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 924 | if ((dev_idle_ctrl & CSE_DEV_IDLE) == CSE_DEV_IDLE) |
| 925 | return DEV_IDLE; |
| 926 | |
| 927 | return DEV_ACTIVE; |
| 928 | } |
| 929 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 930 | static enum cse_device_state ensure_cse_active(pci_devfn_t dev) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 931 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 932 | if (!disable_cse_idle(dev)) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 933 | return DEV_IDLE; |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 934 | pci_or_config32(dev, PCI_COMMAND, PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 935 | |
| 936 | return DEV_ACTIVE; |
| 937 | } |
| 938 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 939 | static void ensure_cse_idle(pci_devfn_t dev) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 940 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 941 | enable_cse_idle(dev); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 942 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 943 | pci_and_config32(dev, PCI_COMMAND, ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER)); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 944 | } |
| 945 | |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 946 | bool set_cse_device_state(unsigned int devfn, enum cse_device_state requested_state) |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 947 | { |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 948 | enum cse_device_state current_state = get_cse_device_state(devfn); |
| 949 | pci_devfn_t dev = PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn)); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 950 | |
| 951 | if (current_state == requested_state) |
| 952 | return true; |
| 953 | |
| 954 | if (requested_state == DEV_ACTIVE) |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 955 | return ensure_cse_active(dev) == requested_state; |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 956 | else |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 957 | ensure_cse_idle(dev); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 958 | |
| 959 | return true; |
| 960 | } |
| 961 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 962 | #if ENV_RAMSTAGE |
| 963 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 964 | static struct device_operations cse_ops = { |
Subrata Banik | 38abbda | 2021-09-30 13:15:50 +0530 | [diff] [blame] | 965 | .set_resources = pci_dev_set_resources, |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 966 | .read_resources = pci_dev_read_resources, |
| 967 | .enable_resources = pci_dev_enable_resources, |
| 968 | .init = pci_dev_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 969 | .ops_pci = &pci_dev_ops_pci, |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 970 | }; |
| 971 | |
Hannah Williams | 6314215 | 2017-06-12 14:03:18 -0700 | [diff] [blame] | 972 | static const unsigned short pci_device_ids[] = { |
| 973 | PCI_DEVICE_ID_INTEL_APL_CSE0, |
| 974 | PCI_DEVICE_ID_INTEL_GLK_CSE0, |
Andrey Petrov | 0405de9 | 2017-06-05 13:25:29 -0700 | [diff] [blame] | 975 | PCI_DEVICE_ID_INTEL_CNL_CSE0, |
Subrata Banik | d0586d2 | 2017-11-27 13:28:41 +0530 | [diff] [blame] | 976 | PCI_DEVICE_ID_INTEL_SKL_CSE0, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 977 | PCI_DEVICE_ID_INTEL_LWB_CSE0, |
| 978 | PCI_DEVICE_ID_INTEL_LWB_CSE0_SUPER, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 979 | PCI_DEVICE_ID_INTEL_CNP_H_CSE0, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 980 | PCI_DEVICE_ID_INTEL_ICL_CSE0, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 981 | PCI_DEVICE_ID_INTEL_CMP_CSE0, |
Gaggery Tsai | 12a651c | 2019-12-05 11:23:20 -0800 | [diff] [blame] | 982 | PCI_DEVICE_ID_INTEL_CMP_H_CSE0, |
Ravi Sarawadi | 6b5bf40 | 2019-10-21 22:25:04 -0700 | [diff] [blame] | 983 | PCI_DEVICE_ID_INTEL_TGL_CSE0, |
Jeremy Soller | 191a8d7 | 2021-08-10 14:06:51 -0600 | [diff] [blame] | 984 | PCI_DEVICE_ID_INTEL_TGL_H_CSE0, |
Tan, Lean Sheng | 2613609 | 2020-01-20 19:13:56 -0800 | [diff] [blame] | 985 | PCI_DEVICE_ID_INTEL_MCC_CSE0, |
| 986 | PCI_DEVICE_ID_INTEL_MCC_CSE1, |
| 987 | PCI_DEVICE_ID_INTEL_MCC_CSE2, |
| 988 | PCI_DEVICE_ID_INTEL_MCC_CSE3, |
Meera Ravindranath | 3f4af0d | 2020-02-12 16:01:22 +0530 | [diff] [blame] | 989 | PCI_DEVICE_ID_INTEL_JSP_CSE0, |
| 990 | PCI_DEVICE_ID_INTEL_JSP_CSE1, |
| 991 | PCI_DEVICE_ID_INTEL_JSP_CSE2, |
| 992 | PCI_DEVICE_ID_INTEL_JSP_CSE3, |
Subrata Banik | f672f7f | 2020-08-03 14:29:25 +0530 | [diff] [blame] | 993 | PCI_DEVICE_ID_INTEL_ADP_P_CSE0, |
| 994 | PCI_DEVICE_ID_INTEL_ADP_P_CSE1, |
| 995 | PCI_DEVICE_ID_INTEL_ADP_P_CSE2, |
| 996 | PCI_DEVICE_ID_INTEL_ADP_P_CSE3, |
| 997 | PCI_DEVICE_ID_INTEL_ADP_S_CSE0, |
| 998 | PCI_DEVICE_ID_INTEL_ADP_S_CSE1, |
| 999 | PCI_DEVICE_ID_INTEL_ADP_S_CSE2, |
| 1000 | PCI_DEVICE_ID_INTEL_ADP_S_CSE3, |
Varshit Pandya | f4d98fdd2 | 2021-01-17 18:39:29 +0530 | [diff] [blame] | 1001 | PCI_DEVICE_ID_INTEL_ADP_M_CSE0, |
| 1002 | PCI_DEVICE_ID_INTEL_ADP_M_CSE1, |
| 1003 | PCI_DEVICE_ID_INTEL_ADP_M_CSE2, |
| 1004 | PCI_DEVICE_ID_INTEL_ADP_M_CSE3, |
Hannah Williams | 6314215 | 2017-06-12 14:03:18 -0700 | [diff] [blame] | 1005 | 0, |
| 1006 | }; |
| 1007 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 1008 | static const struct pci_driver cse_driver __pci_driver = { |
| 1009 | .ops = &cse_ops, |
| 1010 | .vendor = PCI_VENDOR_ID_INTEL, |
| 1011 | /* SoC/chipset needs to provide PCI device ID */ |
Andrey Petrov | 0405de9 | 2017-06-05 13:25:29 -0700 | [diff] [blame] | 1012 | .devices = pci_device_ids |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 1013 | }; |
| 1014 | |
| 1015 | #endif |