blob: d697c84a97259074f47b4ab39fe430ca3ade601b [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Andrey Petrov04a72c42017-03-01 15:51:57 -08002
Subrata Banikc6e25522021-09-30 18:14:09 +05303#define __SIMPLE_DEVICE__
4
Subrata Banik05e06cd2017-11-09 15:04:09 +05305#include <assert.h>
Andrey Petrov04a72c42017-03-01 15:51:57 -08006#include <commonlib/helpers.h>
7#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02008#include <device/mmio.h>
Andrey Petrov04a72c42017-03-01 15:51:57 -08009#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>
Subrata Banik80c92892022-02-01 00:26:55 +053014#include <intelblocks/pmclib.h>
Martin Roth8c974502022-11-20 17:56:44 -070015#include <intelblocks/post_codes.h>
Sean Rhodes69ed3ed2021-04-30 16:38:17 +010016#include <option.h>
Tim Wawrzynczak09635f42021-06-18 10:08:47 -060017#include <security/vboot/misc.h>
18#include <security/vboot/vboot_common.h>
Sean Rhodes69ed3ed2021-04-30 16:38:17 +010019#include <soc/intel/common/reset.h>
Subrata Banik05e06cd2017-11-09 15:04:09 +053020#include <soc/iomap.h>
Andrey Petrov04a72c42017-03-01 15:51:57 -080021#include <soc/pci_devs.h>
Sridhar Siricilla8e465452019-09-23 20:59:38 +053022#include <soc/me.h>
Andrey Petrov04a72c42017-03-01 15:51:57 -080023#include <string.h>
24#include <timer.h>
Sean Rhodes69ed3ed2021-04-30 16:38:17 +010025#include <types.h>
Andrey Petrov04a72c42017-03-01 15:51:57 -080026
Subrata Banik801dbf42022-06-01 07:56:40 +000027#define HECI_BASE_SIZE (4 * KiB)
28
Subrata Banik5c08c732017-11-13 14:54:37 +053029#define MAX_HECI_MESSAGE_RETRY_COUNT 5
30
Andrey Petrov04a72c42017-03-01 15:51:57 -080031/* Wait up to 15 sec for HECI to get ready */
Subrata Banik03aef282021-09-28 18:10:24 +053032#define HECI_DELAY_READY_MS (15 * 1000)
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010033/* Wait up to 100 usec between circular buffer polls */
Subrata Banik03aef282021-09-28 18:10:24 +053034#define HECI_DELAY_US 100
Andrey Petrov04a72c42017-03-01 15:51:57 -080035/* Wait up to 5 sec for CSE to chew something we sent */
Subrata Banik03aef282021-09-28 18:10:24 +053036#define HECI_SEND_TIMEOUT_MS (5 * 1000)
Andrey Petrov04a72c42017-03-01 15:51:57 -080037/* Wait up to 5 sec for CSE to blurp a reply */
Subrata Banik03aef282021-09-28 18:10:24 +053038#define HECI_READ_TIMEOUT_MS (5 * 1000)
Subrata Banika219edb2021-09-25 15:02:37 +053039/* Wait up to 1 ms for CSE CIP */
Subrata Banik03aef282021-09-28 18:10:24 +053040#define HECI_CIP_TIMEOUT_US 1000
Subrata Banikf5765812021-09-30 13:37:10 +053041/* Wait up to 5 seconds for CSE to boot from RO(BP1) */
42#define CSE_DELAY_BOOT_TO_RO_MS (5 * 1000)
Andrey Petrov04a72c42017-03-01 15:51:57 -080043
44#define SLOT_SIZE sizeof(uint32_t)
45
46#define MMIO_CSE_CB_WW 0x00
47#define MMIO_HOST_CSR 0x04
48#define MMIO_CSE_CB_RW 0x08
49#define MMIO_CSE_CSR 0x0c
Subrata Banika219edb2021-09-25 15:02:37 +053050#define MMIO_CSE_DEVIDLE 0x800
51#define CSE_DEV_IDLE (1 << 2)
52#define CSE_DEV_CIP (1 << 0)
Andrey Petrov04a72c42017-03-01 15:51:57 -080053
54#define CSR_IE (1 << 0)
55#define CSR_IS (1 << 1)
56#define CSR_IG (1 << 2)
57#define CSR_READY (1 << 3)
58#define CSR_RESET (1 << 4)
59#define CSR_RP_START 8
60#define CSR_RP (((1 << 8) - 1) << CSR_RP_START)
61#define CSR_WP_START 16
62#define CSR_WP (((1 << 8) - 1) << CSR_WP_START)
63#define CSR_CBD_START 24
64#define CSR_CBD (((1 << 8) - 1) << CSR_CBD_START)
65
66#define MEI_HDR_IS_COMPLETE (1 << 31)
67#define MEI_HDR_LENGTH_START 16
68#define MEI_HDR_LENGTH_SIZE 9
69#define MEI_HDR_LENGTH (((1 << MEI_HDR_LENGTH_SIZE) - 1) \
70 << MEI_HDR_LENGTH_START)
71#define MEI_HDR_HOST_ADDR_START 8
72#define MEI_HDR_HOST_ADDR (((1 << 8) - 1) << MEI_HDR_HOST_ADDR_START)
73#define MEI_HDR_CSE_ADDR_START 0
74#define MEI_HDR_CSE_ADDR (((1 << 8) - 1) << MEI_HDR_CSE_ADDR_START)
75
Subrata Banik38abbda2021-09-30 13:15:50 +053076/* Get HECI BAR 0 from PCI configuration space */
Subrata Banikc6e25522021-09-30 18:14:09 +053077static uintptr_t get_cse_bar(pci_devfn_t dev)
Subrata Banik38abbda2021-09-30 13:15:50 +053078{
79 uintptr_t bar;
80
Subrata Banikc6e25522021-09-30 18:14:09 +053081 bar = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
Subrata Banik38abbda2021-09-30 13:15:50 +053082 assert(bar != 0);
83 /*
84 * Bits 31-12 are the base address as per EDS for SPI,
85 * Don't care about 0-11 bit
86 */
87 return bar & ~PCI_BASE_ADDRESS_MEM_ATTR_MASK;
88}
Andrey Petrov04a72c42017-03-01 15:51:57 -080089
Subrata Banik801dbf42022-06-01 07:56:40 +000090static void heci_assign_resource(pci_devfn_t dev, uintptr_t tempbar)
91{
92 u16 pcireg;
93
94 /* Assign Resources */
95 /* Clear BIT 1-2 of Command Register */
96 pcireg = pci_read_config16(dev, PCI_COMMAND);
97 pcireg &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
98 pci_write_config16(dev, PCI_COMMAND, pcireg);
99
100 /* Program Temporary BAR for HECI device */
101 pci_write_config32(dev, PCI_BASE_ADDRESS_0, tempbar);
102 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0x0);
103
104 /* Enable Bus Master and MMIO Space */
105 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
106}
107
Andrey Petrov04a72c42017-03-01 15:51:57 -0800108/*
Subrata Banik0b92aa62022-06-01 06:54:44 +0000109 * Initialize the CSE device with provided temporary BAR. If BAR is 0 use a
Andrey Petrov04a72c42017-03-01 15:51:57 -0800110 * default. This is intended for pre-mem usage only where BARs haven't been
111 * assigned yet and devices are not enabled.
112 */
Subrata Banik0b92aa62022-06-01 06:54:44 +0000113void cse_init(uintptr_t tempbar)
Andrey Petrov04a72c42017-03-01 15:51:57 -0800114{
Elyes HAOUAS68c851b2018-06-12 22:06:09 +0200115 pci_devfn_t dev = PCH_DEV_CSE;
Subrata Banikc6e25522021-09-30 18:14:09 +0530116
Matt DeVillierf711bf02022-01-25 19:48:38 -0600117 /* Check if device enabled */
118 if (!is_cse_enabled())
119 return;
120
Andrey Petrov04a72c42017-03-01 15:51:57 -0800121 /* Assume it is already initialized, nothing else to do */
Subrata Banikc6e25522021-09-30 18:14:09 +0530122 if (get_cse_bar(dev))
Andrey Petrov04a72c42017-03-01 15:51:57 -0800123 return;
124
125 /* Use default pre-ram bar */
126 if (!tempbar)
127 tempbar = HECI1_BASE_ADDRESS;
128
Subrata Banik801dbf42022-06-01 07:56:40 +0000129 /* Assign HECI resource and enable the resource */
130 heci_assign_resource(dev, tempbar);
Sridhar Siricillacb2fd202021-06-09 19:27:06 +0530131
132 /* Trigger HECI Reset and make Host ready for communication with CSE */
133 heci_reset();
Subrata Banik05e06cd2017-11-09 15:04:09 +0530134}
135
Subrata Banikc6e25522021-09-30 18:14:09 +0530136static uint32_t read_bar(pci_devfn_t dev, uint32_t offset)
Andrey Petrov04a72c42017-03-01 15:51:57 -0800137{
Subrata Banikc6e25522021-09-30 18:14:09 +0530138 return read32p(get_cse_bar(dev) + offset);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800139}
140
Subrata Banikc6e25522021-09-30 18:14:09 +0530141static void write_bar(pci_devfn_t dev, uint32_t offset, uint32_t val)
Andrey Petrov04a72c42017-03-01 15:51:57 -0800142{
Subrata Banikc6e25522021-09-30 18:14:09 +0530143 return write32p(get_cse_bar(dev) + offset, val);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800144}
145
146static uint32_t read_cse_csr(void)
147{
Subrata Banikc6e25522021-09-30 18:14:09 +0530148 return read_bar(PCH_DEV_CSE, MMIO_CSE_CSR);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800149}
150
151static uint32_t read_host_csr(void)
152{
Subrata Banikc6e25522021-09-30 18:14:09 +0530153 return read_bar(PCH_DEV_CSE, MMIO_HOST_CSR);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800154}
155
156static void write_host_csr(uint32_t data)
157{
Subrata Banikc6e25522021-09-30 18:14:09 +0530158 write_bar(PCH_DEV_CSE, MMIO_HOST_CSR, data);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800159}
160
161static size_t filled_slots(uint32_t data)
162{
163 uint8_t wp, rp;
164 rp = data >> CSR_RP_START;
165 wp = data >> CSR_WP_START;
Elyes Haouas9018dee2022-11-18 15:07:33 +0100166 return (uint8_t)(wp - rp);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800167}
168
169static size_t cse_filled_slots(void)
170{
171 return filled_slots(read_cse_csr());
172}
173
174static size_t host_empty_slots(void)
175{
176 uint32_t csr;
177 csr = read_host_csr();
178
179 return ((csr & CSR_CBD) >> CSR_CBD_START) - filled_slots(csr);
180}
181
182static void clear_int(void)
183{
184 uint32_t csr;
185 csr = read_host_csr();
186 csr |= CSR_IS;
187 write_host_csr(csr);
188}
189
190static uint32_t read_slot(void)
191{
Subrata Banikc6e25522021-09-30 18:14:09 +0530192 return read_bar(PCH_DEV_CSE, MMIO_CSE_CB_RW);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800193}
194
195static void write_slot(uint32_t val)
196{
Subrata Banikc6e25522021-09-30 18:14:09 +0530197 write_bar(PCH_DEV_CSE, MMIO_CSE_CB_WW, val);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800198}
199
200static int wait_write_slots(size_t cnt)
201{
202 struct stopwatch sw;
203
Subrata Banik03aef282021-09-28 18:10:24 +0530204 stopwatch_init_msecs_expire(&sw, HECI_SEND_TIMEOUT_MS);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800205 while (host_empty_slots() < cnt) {
Subrata Banik03aef282021-09-28 18:10:24 +0530206 udelay(HECI_DELAY_US);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800207 if (stopwatch_expired(&sw)) {
208 printk(BIOS_ERR, "HECI: timeout, buffer not drained\n");
209 return 0;
210 }
211 }
212 return 1;
213}
214
215static int wait_read_slots(size_t cnt)
216{
217 struct stopwatch sw;
218
Subrata Banik03aef282021-09-28 18:10:24 +0530219 stopwatch_init_msecs_expire(&sw, HECI_READ_TIMEOUT_MS);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800220 while (cse_filled_slots() < cnt) {
Subrata Banik03aef282021-09-28 18:10:24 +0530221 udelay(HECI_DELAY_US);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800222 if (stopwatch_expired(&sw)) {
223 printk(BIOS_ERR, "HECI: timed out reading answer!\n");
224 return 0;
225 }
226 }
227 return 1;
228}
229
230/* get number of full 4-byte slots */
231static size_t bytes_to_slots(size_t bytes)
232{
233 return ALIGN_UP(bytes, SLOT_SIZE) / SLOT_SIZE;
234}
235
236static int cse_ready(void)
237{
238 uint32_t csr;
239 csr = read_cse_csr();
240 return csr & CSR_READY;
241}
242
Sridhar Siricilla8e465452019-09-23 20:59:38 +0530243static bool cse_check_hfs1_com(int mode)
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530244{
245 union me_hfsts1 hfs1;
246 hfs1.data = me_read_config32(PCI_ME_HFSTS1);
Sridhar Siricilla8e465452019-09-23 20:59:38 +0530247 return hfs1.fields.operation_mode == mode;
248}
249
250bool cse_is_hfs1_cws_normal(void)
251{
252 union me_hfsts1 hfs1;
253 hfs1.data = me_read_config32(PCI_ME_HFSTS1);
254 if (hfs1.fields.working_state == ME_HFS1_CWS_NORMAL)
255 return true;
256 return false;
257}
258
259bool cse_is_hfs1_com_normal(void)
260{
261 return cse_check_hfs1_com(ME_HFS1_COM_NORMAL);
262}
263
264bool cse_is_hfs1_com_secover_mei_msg(void)
265{
266 return cse_check_hfs1_com(ME_HFS1_COM_SECOVER_MEI_MSG);
267}
268
269bool cse_is_hfs1_com_soft_temp_disable(void)
270{
271 return cse_check_hfs1_com(ME_HFS1_COM_SOFT_TEMP_DISABLE);
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530272}
273
Subrata Banike74ebcd2021-12-27 10:49:19 +0000274/*
Sridhar Siricilla90a43932022-09-12 10:37:17 +0530275 * Starting from TGL platform, HFSTS1.spi_protection_mode replaces mfg_mode to indicate
276 * SPI protection status as well as end-of-manufacturing(EOM) status where EOM flow is
277 * triggered in single staged operation (either through first boot with required MFIT
278 * configuratin or FPT /CLOSEMANUF).
279 * In staged manufacturing flow, spi_protection_mode alone doesn't indicate the EOM status.
Subrata Banike74ebcd2021-12-27 10:49:19 +0000280 *
Sridhar Siricilla90a43932022-09-12 10:37:17 +0530281 * HFSTS1.spi_protection_mode description:
282 * mfg_mode = 0 means SPI protection is on.
Subrata Banike74ebcd2021-12-27 10:49:19 +0000283 * mfg_mode = 1 means SPI is unprotected.
284 */
285bool cse_is_hfs1_spi_protected(void)
286{
287 union me_hfsts1 hfs1;
288 hfs1.data = me_read_config32(PCI_ME_HFSTS1);
289 return !hfs1.fields.mfg_mode;
290}
291
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530292bool cse_is_hfs3_fw_sku_lite(void)
Sridhar Siricilla3465d272020-02-06 15:31:04 +0530293{
294 union me_hfsts3 hfs3;
295 hfs3.data = me_read_config32(PCI_ME_HFSTS3);
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530296 return hfs3.fields.fw_sku == ME_HFS3_FW_SKU_LITE;
Sridhar Siricilla3465d272020-02-06 15:31:04 +0530297}
298
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530299/* Makes the host ready to communicate with CSE */
Sridhar Siricillaff072e62019-11-27 14:55:16 +0530300void cse_set_host_ready(void)
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530301{
302 uint32_t csr;
303 csr = read_host_csr();
304 csr &= ~CSR_RESET;
305 csr |= (CSR_IG | CSR_READY);
306 write_host_csr(csr);
307}
308
Sridhar Siricillaff072e62019-11-27 14:55:16 +0530309/* Polls for ME mode ME_HFS1_COM_SECOVER_MEI_MSG for 15 seconds */
310uint8_t cse_wait_sec_override_mode(void)
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530311{
312 struct stopwatch sw;
Subrata Banik03aef282021-09-28 18:10:24 +0530313 stopwatch_init_msecs_expire(&sw, HECI_DELAY_READY_MS);
Sridhar Siricilla8e465452019-09-23 20:59:38 +0530314 while (!cse_is_hfs1_com_secover_mei_msg()) {
Subrata Banik03aef282021-09-28 18:10:24 +0530315 udelay(HECI_DELAY_US);
Sridhar Siricillaff072e62019-11-27 14:55:16 +0530316 if (stopwatch_expired(&sw)) {
317 printk(BIOS_ERR, "HECI: Timed out waiting for SEC_OVERRIDE mode!\n");
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530318 return 0;
Sridhar Siricillaff072e62019-11-27 14:55:16 +0530319 }
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530320 }
Rob Barnesd522f382022-09-12 06:31:47 -0600321 printk(BIOS_DEBUG, "HECI: CSE took %lld ms to enter security override mode\n",
Sridhar Siricillaff072e62019-11-27 14:55:16 +0530322 stopwatch_duration_msecs(&sw));
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530323 return 1;
324}
325
Sridhar Siricilla09ea3712019-11-12 23:35:50 +0530326/*
327 * Polls for CSE's current operation mode 'Soft Temporary Disable'.
328 * The CSE enters the current operation mode when it boots from RO(BP1).
329 */
330uint8_t cse_wait_com_soft_temp_disable(void)
331{
332 struct stopwatch sw;
Subrata Banikf5765812021-09-30 13:37:10 +0530333 stopwatch_init_msecs_expire(&sw, CSE_DELAY_BOOT_TO_RO_MS);
Sridhar Siricilla09ea3712019-11-12 23:35:50 +0530334 while (!cse_is_hfs1_com_soft_temp_disable()) {
Subrata Banik03aef282021-09-28 18:10:24 +0530335 udelay(HECI_DELAY_US);
Sridhar Siricilla09ea3712019-11-12 23:35:50 +0530336 if (stopwatch_expired(&sw)) {
337 printk(BIOS_ERR, "HECI: Timed out waiting for CSE to boot from RO!\n");
338 return 0;
339 }
340 }
Rob Barnesd522f382022-09-12 06:31:47 -0600341 printk(BIOS_SPEW, "HECI: CSE took %lld ms to boot from RO\n",
Sridhar Siricilla09ea3712019-11-12 23:35:50 +0530342 stopwatch_duration_msecs(&sw));
343 return 1;
344}
345
Andrey Petrov04a72c42017-03-01 15:51:57 -0800346static int wait_heci_ready(void)
347{
348 struct stopwatch sw;
349
Subrata Banik03aef282021-09-28 18:10:24 +0530350 stopwatch_init_msecs_expire(&sw, HECI_DELAY_READY_MS);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800351 while (!cse_ready()) {
Subrata Banik03aef282021-09-28 18:10:24 +0530352 udelay(HECI_DELAY_US);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800353 if (stopwatch_expired(&sw))
354 return 0;
355 }
356
357 return 1;
358}
359
360static void host_gen_interrupt(void)
361{
362 uint32_t csr;
363 csr = read_host_csr();
364 csr |= CSR_IG;
365 write_host_csr(csr);
366}
367
368static size_t hdr_get_length(uint32_t hdr)
369{
370 return (hdr & MEI_HDR_LENGTH) >> MEI_HDR_LENGTH_START;
371}
372
373static int
374send_one_message(uint32_t hdr, const void *buff)
375{
376 size_t pend_len, pend_slots, remainder, i;
377 uint32_t tmp;
378 const uint32_t *p = buff;
379
380 /* Get space for the header */
381 if (!wait_write_slots(1))
382 return 0;
383
384 /* First, write header */
385 write_slot(hdr);
386
387 pend_len = hdr_get_length(hdr);
388 pend_slots = bytes_to_slots(pend_len);
389
390 if (!wait_write_slots(pend_slots))
391 return 0;
392
393 /* Write the body in whole slots */
394 i = 0;
395 while (i < ALIGN_DOWN(pend_len, SLOT_SIZE)) {
396 write_slot(*p++);
397 i += SLOT_SIZE;
398 }
399
400 remainder = pend_len % SLOT_SIZE;
401 /* Pad to 4 bytes not touching caller's buffer */
402 if (remainder) {
403 memcpy(&tmp, p, remainder);
404 write_slot(tmp);
405 }
406
407 host_gen_interrupt();
408
409 /* Make sure nothing bad happened during transmission */
410 if (!cse_ready())
411 return 0;
412
413 return pend_len;
414}
415
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530416/*
417 * Send message msg of size len to host from host_addr to cse_addr.
Sridhar Siricillac760e41a2022-08-15 21:10:58 +0530418 * Returns CSE_TX_RX_SUCCESS on success and other enum values on failure scenarios.
419 * Also, in case of errors, heci_reset() is triggered.
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530420 */
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530421static enum cse_tx_rx_status
Andrey Petrov04a72c42017-03-01 15:51:57 -0800422heci_send(const void *msg, size_t len, uint8_t host_addr, uint8_t client_addr)
423{
Subrata Banik5c08c732017-11-13 14:54:37 +0530424 uint8_t retry;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800425 uint32_t csr, hdr;
Subrata Banik5c08c732017-11-13 14:54:37 +0530426 size_t sent, remaining, cb_size, max_length;
427 const uint8_t *p;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800428
429 if (!msg || !len)
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530430 return CSE_TX_ERR_INPUT;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800431
432 clear_int();
433
Subrata Banik5c08c732017-11-13 14:54:37 +0530434 for (retry = 0; retry < MAX_HECI_MESSAGE_RETRY_COUNT; retry++) {
435 p = msg;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800436
Subrata Banik5c08c732017-11-13 14:54:37 +0530437 if (!wait_heci_ready()) {
438 printk(BIOS_ERR, "HECI: not ready\n");
439 continue;
440 }
Andrey Petrov04a72c42017-03-01 15:51:57 -0800441
Subrata Banik4a722f52017-11-13 14:56:42 +0530442 csr = read_host_csr();
Subrata Banik5c08c732017-11-13 14:54:37 +0530443 cb_size = ((csr & CSR_CBD) >> CSR_CBD_START) * SLOT_SIZE;
444 /*
445 * Reserve one slot for the header. Limit max message
446 * length by 9 bits that are available in the header.
447 */
448 max_length = MIN(cb_size, (1 << MEI_HDR_LENGTH_SIZE) - 1)
449 - SLOT_SIZE;
450 remaining = len;
451
452 /*
453 * Fragment the message into smaller messages not exceeding
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +0100454 * useful circular buffer length. Mark last message complete.
Subrata Banik5c08c732017-11-13 14:54:37 +0530455 */
456 do {
457 hdr = MIN(max_length, remaining)
458 << MEI_HDR_LENGTH_START;
459 hdr |= client_addr << MEI_HDR_CSE_ADDR_START;
460 hdr |= host_addr << MEI_HDR_HOST_ADDR_START;
461 hdr |= (MIN(max_length, remaining) == remaining) ?
Lee Leahy68ab0b52017-03-10 13:42:34 -0800462 MEI_HDR_IS_COMPLETE : 0;
Subrata Banik5c08c732017-11-13 14:54:37 +0530463 sent = send_one_message(hdr, p);
464 p += sent;
465 remaining -= sent;
466 } while (remaining > 0 && sent != 0);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800467
Subrata Banik5c08c732017-11-13 14:54:37 +0530468 if (!remaining)
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530469 return CSE_TX_RX_SUCCESS;
Subrata Banik5c08c732017-11-13 14:54:37 +0530470 }
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530471
Sridhar Siricilla1506b772022-03-05 10:02:25 +0530472 printk(BIOS_DEBUG, "HECI: Trigger HECI reset\n");
473 heci_reset();
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530474 return CSE_TX_ERR_CSE_NOT_READY;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800475}
476
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530477static enum cse_tx_rx_status
478recv_one_message(uint32_t *hdr, void *buff, size_t maxlen, size_t *recv_len)
Andrey Petrov04a72c42017-03-01 15:51:57 -0800479{
480 uint32_t reg, *p = buff;
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530481 size_t recv_slots, remainder, i;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800482
483 /* first get the header */
484 if (!wait_read_slots(1))
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530485 return CSE_RX_ERR_TIMEOUT;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800486
487 *hdr = read_slot();
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530488 *recv_len = hdr_get_length(*hdr);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800489
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530490 if (!*recv_len)
Andrey Petrov04a72c42017-03-01 15:51:57 -0800491 printk(BIOS_WARNING, "HECI: message is zero-sized\n");
492
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530493 recv_slots = bytes_to_slots(*recv_len);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800494
495 i = 0;
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530496 if (*recv_len > maxlen) {
Andrey Petrov04a72c42017-03-01 15:51:57 -0800497 printk(BIOS_ERR, "HECI: response is too big\n");
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530498 return CSE_RX_ERR_RESP_LEN_MISMATCH;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800499 }
500
501 /* wait for the rest of messages to arrive */
502 wait_read_slots(recv_slots);
503
504 /* fetch whole slots first */
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530505 while (i < ALIGN_DOWN(*recv_len, SLOT_SIZE)) {
Andrey Petrov04a72c42017-03-01 15:51:57 -0800506 *p++ = read_slot();
507 i += SLOT_SIZE;
508 }
509
Subrata Banik5c08c732017-11-13 14:54:37 +0530510 /*
511 * If ME is not ready, something went wrong and
512 * we received junk
513 */
514 if (!cse_ready())
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530515 return CSE_RX_ERR_CSE_NOT_READY;
Subrata Banik5c08c732017-11-13 14:54:37 +0530516
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530517 remainder = *recv_len % SLOT_SIZE;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800518
519 if (remainder) {
520 reg = read_slot();
521 memcpy(p, &reg, remainder);
522 }
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530523 return CSE_TX_RX_SUCCESS;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800524}
525
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530526/*
527 * Receive message into buff not exceeding maxlen. Message is considered
528 * successfully received if a 'complete' indication is read from ME side
529 * and there was enough space in the buffer to fit that message. maxlen
Sridhar Siricillac760e41a2022-08-15 21:10:58 +0530530 * is updated with size of message that was received.
531 * Returns CSE_TX_RX_SUCCESS on success and other enum values on failure scenarios.
532 * Also, in case of errors, heci_reset() is triggered.
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530533 */
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530534static enum cse_tx_rx_status heci_receive(void *buff, size_t *maxlen)
Andrey Petrov04a72c42017-03-01 15:51:57 -0800535{
Subrata Banik5c08c732017-11-13 14:54:37 +0530536 uint8_t retry;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800537 size_t left, received;
538 uint32_t hdr = 0;
Subrata Banik5c08c732017-11-13 14:54:37 +0530539 uint8_t *p;
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530540 enum cse_tx_rx_status ret = CSE_RX_ERR_TIMEOUT;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800541
542 if (!buff || !maxlen || !*maxlen)
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530543 return CSE_RX_ERR_INPUT;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800544
Andrey Petrov04a72c42017-03-01 15:51:57 -0800545 clear_int();
546
Subrata Banik5c08c732017-11-13 14:54:37 +0530547 for (retry = 0; retry < MAX_HECI_MESSAGE_RETRY_COUNT; retry++) {
548 p = buff;
549 left = *maxlen;
550
551 if (!wait_heci_ready()) {
552 printk(BIOS_ERR, "HECI: not ready\n");
553 continue;
554 }
555
556 /*
557 * Receive multiple packets until we meet one marked
558 * complete or we run out of space in caller-provided buffer.
559 */
560 do {
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530561 ret = recv_one_message(&hdr, p, left, &received);
562 if (ret) {
Elyes HAOUAS3d450002018-08-09 18:55:58 +0200563 printk(BIOS_ERR, "HECI: Failed to receive!\n");
Sridhar Siricilla1506b772022-03-05 10:02:25 +0530564 goto CSE_RX_ERR_HANDLE;
Lijian Zhaoc50296d2017-12-15 19:10:18 -0800565 }
Subrata Banik5c08c732017-11-13 14:54:37 +0530566 left -= received;
567 p += received;
568 /* If we read out everything ping to send more */
569 if (!(hdr & MEI_HDR_IS_COMPLETE) && !cse_filled_slots())
570 host_gen_interrupt();
571 } while (received && !(hdr & MEI_HDR_IS_COMPLETE) && left > 0);
572
573 if ((hdr & MEI_HDR_IS_COMPLETE) && received) {
Elyes Haouas9018dee2022-11-18 15:07:33 +0100574 *maxlen = p - (uint8_t *)buff;
Johnny Lina3e68c92022-08-09 15:36:30 +0800575 if (CONFIG(SOC_INTEL_CSE_SERVER_SKU))
576 clear_int();
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530577 return CSE_TX_RX_SUCCESS;
Subrata Banik5c08c732017-11-13 14:54:37 +0530578 }
Andrey Petrov04a72c42017-03-01 15:51:57 -0800579 }
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530580
Sridhar Siricilla1506b772022-03-05 10:02:25 +0530581CSE_RX_ERR_HANDLE:
582 printk(BIOS_DEBUG, "HECI: Trigger HECI Reset\n");
583 heci_reset();
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530584 return CSE_RX_ERR_CSE_NOT_READY;
Andrey Petrov04a72c42017-03-01 15:51:57 -0800585}
586
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530587enum cse_tx_rx_status heci_send_receive(const void *snd_msg, size_t snd_sz, void *rcv_msg,
588 size_t *rcv_sz, uint8_t cse_addr)
Sridhar Siricillaa5208f52019-08-30 17:10:24 +0530589{
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530590 enum cse_tx_rx_status ret;
591
592 ret = heci_send(snd_msg, snd_sz, BIOS_HOST_ADDR, cse_addr);
593 if (ret) {
Sridhar Siricillaa5208f52019-08-30 17:10:24 +0530594 printk(BIOS_ERR, "HECI: send Failed\n");
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530595 return ret;
Sridhar Siricillaa5208f52019-08-30 17:10:24 +0530596 }
597
598 if (rcv_msg != NULL) {
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530599 ret = heci_receive(rcv_msg, rcv_sz);
600 if (ret) {
Sridhar Siricillaa5208f52019-08-30 17:10:24 +0530601 printk(BIOS_ERR, "HECI: receive Failed\n");
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530602 return ret;
Sridhar Siricillaa5208f52019-08-30 17:10:24 +0530603 }
604 }
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530605 return ret;
Sridhar Siricillaa5208f52019-08-30 17:10:24 +0530606}
607
Andrey Petrov04a72c42017-03-01 15:51:57 -0800608/*
609 * Attempt to reset the device. This is useful when host and ME are out
610 * of sync during transmission or ME didn't understand the message.
611 */
612int heci_reset(void)
613{
614 uint32_t csr;
615
Duncan Laurie15ca9032020-11-05 10:09:07 -0800616 /* Clear post code to prevent eventlog entry from unknown code. */
Martin Roth8c974502022-11-20 17:56:44 -0700617 post_code(POST_CODE_ZERO);
Duncan Laurie15ca9032020-11-05 10:09:07 -0800618
Andrey Petrov04a72c42017-03-01 15:51:57 -0800619 /* Send reset request */
620 csr = read_host_csr();
Sridhar Siricillab9d075b2019-08-31 11:38:33 +0530621 csr |= (CSR_RESET | CSR_IG);
Andrey Petrov04a72c42017-03-01 15:51:57 -0800622 write_host_csr(csr);
623
624 if (wait_heci_ready()) {
625 /* Device is back on its imaginary feet, clear reset */
Sridhar Siricillaff072e62019-11-27 14:55:16 +0530626 cse_set_host_ready();
Andrey Petrov04a72c42017-03-01 15:51:57 -0800627 return 1;
628 }
629
630 printk(BIOS_CRIT, "HECI: reset failed\n");
631
632 return 0;
633}
634
Subrata Banik3710e992021-09-30 16:59:09 +0530635bool is_cse_devfn_visible(unsigned int devfn)
Sridhar Siricilla2cc66912019-08-31 11:20:34 +0530636{
Subrata Banik3710e992021-09-30 16:59:09 +0530637 int slot = PCI_SLOT(devfn);
638 int func = PCI_FUNC(devfn);
Sridhar Siricilla2cc66912019-08-31 11:20:34 +0530639
Subrata Banik3710e992021-09-30 16:59:09 +0530640 if (!is_devfn_enabled(devfn)) {
641 printk(BIOS_WARNING, "HECI: CSE device %02x.%01x is disabled\n", slot, func);
Sridhar Siricilla2cc66912019-08-31 11:20:34 +0530642 return false;
643 }
644
Subrata Banik3710e992021-09-30 16:59:09 +0530645 if (pci_read_config16(PCI_DEV(0, slot, func), PCI_VENDOR_ID) == 0xFFFF) {
646 printk(BIOS_WARNING, "HECI: CSE device %02x.%01x is hidden\n", slot, func);
Sridhar Siricilla2cc66912019-08-31 11:20:34 +0530647 return false;
648 }
649
650 return true;
651}
652
Subrata Banik3710e992021-09-30 16:59:09 +0530653bool is_cse_enabled(void)
654{
655 return is_cse_devfn_visible(PCH_DEVFN_CSE);
656}
657
Sridhar Siricilla2cc66912019-08-31 11:20:34 +0530658uint32_t me_read_config32(int offset)
659{
660 return pci_read_config32(PCH_DEV_CSE, offset);
661}
662
Sridhar Siricilla59c7cb7d2020-02-07 11:59:30 +0530663static bool cse_is_global_reset_allowed(void)
664{
665 /*
666 * Allow sending GLOBAL_RESET command only if:
667 * - CSE's current working state is Normal and current operation mode is Normal.
668 * - (or) CSE's current working state is normal and current operation mode can
669 * be Soft Temp Disable or Security Override Mode if CSE's Firmware SKU is
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530670 * Lite.
Sridhar Siricilla59c7cb7d2020-02-07 11:59:30 +0530671 */
672 if (!cse_is_hfs1_cws_normal())
673 return false;
674
675 if (cse_is_hfs1_com_normal())
676 return true;
677
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530678 if (cse_is_hfs3_fw_sku_lite()) {
Sridhar Siricilla59c7cb7d2020-02-07 11:59:30 +0530679 if (cse_is_hfs1_com_soft_temp_disable() || cse_is_hfs1_com_secover_mei_msg())
680 return true;
681 }
682 return false;
683}
684
Sridhar Siricillad415c202019-08-31 14:54:57 +0530685/*
Subrata Banikf463dc02020-09-14 19:04:03 +0530686 * Sends GLOBAL_RESET_REQ cmd to CSE with reset type GLOBAL_RESET.
687 * Returns 0 on failure and 1 on success.
Sridhar Siricillad415c202019-08-31 14:54:57 +0530688 */
Subrata Banikf463dc02020-09-14 19:04:03 +0530689static int cse_request_reset(enum rst_req_type rst_type)
Sridhar Siricillad415c202019-08-31 14:54:57 +0530690{
691 int status;
692 struct mkhi_hdr reply;
693 struct reset_message {
694 struct mkhi_hdr hdr;
695 uint8_t req_origin;
696 uint8_t reset_type;
697 } __packed;
698 struct reset_message msg = {
699 .hdr = {
700 .group_id = MKHI_GROUP_ID_CBM,
Sridhar Siricillae202e672020-01-07 23:36:40 +0530701 .command = MKHI_CBM_GLOBAL_RESET_REQ,
Sridhar Siricillad415c202019-08-31 14:54:57 +0530702 },
703 .req_origin = GR_ORIGIN_BIOS_POST,
704 .reset_type = rst_type
705 };
706 size_t reply_size;
707
Sridhar Siricillaf2eb6872019-12-05 19:54:16 +0530708 printk(BIOS_DEBUG, "HECI: Global Reset(Type:%d) Command\n", rst_type);
Sridhar Siricilla59c7cb7d2020-02-07 11:59:30 +0530709
Sridhar Siricillac2a2d2b2020-02-27 17:16:13 +0530710 if (!(rst_type == GLOBAL_RESET || rst_type == CSE_RESET_ONLY)) {
Sridhar Siricillaf2eb6872019-12-05 19:54:16 +0530711 printk(BIOS_ERR, "HECI: Unsupported reset type is requested\n");
712 return 0;
713 }
Sridhar Siricillad415c202019-08-31 14:54:57 +0530714
Subrata Banikf463dc02020-09-14 19:04:03 +0530715 if (!cse_is_global_reset_allowed() || !is_cse_enabled()) {
Sridhar Siricilla59c7cb7d2020-02-07 11:59:30 +0530716 printk(BIOS_ERR, "HECI: CSE does not meet required prerequisites\n");
717 return 0;
718 }
719
Sridhar Siricillad415c202019-08-31 14:54:57 +0530720 heci_reset();
721
722 reply_size = sizeof(reply);
723 memset(&reply, 0, reply_size);
724
Sridhar Siricillad415c202019-08-31 14:54:57 +0530725 if (rst_type == CSE_RESET_ONLY)
Sridhar Siricillaf2eb6872019-12-05 19:54:16 +0530726 status = heci_send(&msg, sizeof(msg), BIOS_HOST_ADDR, HECI_MKHI_ADDR);
Sridhar Siricillad415c202019-08-31 14:54:57 +0530727 else
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530728 status = heci_send_receive(&msg, sizeof(msg), &reply, &reply_size,
729 HECI_MKHI_ADDR);
Sridhar Siricillad415c202019-08-31 14:54:57 +0530730
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530731 printk(BIOS_DEBUG, "HECI: Global Reset %s!\n", !status ? "success" : "failure");
Sridhar Siricillaf2eb6872019-12-05 19:54:16 +0530732 return status;
Sridhar Siricillad415c202019-08-31 14:54:57 +0530733}
734
Subrata Banikf463dc02020-09-14 19:04:03 +0530735int cse_request_global_reset(void)
736{
737 return cse_request_reset(GLOBAL_RESET);
738}
739
Sridhar Siricillad16187e2019-11-27 16:02:47 +0530740static bool cse_is_hmrfpo_enable_allowed(void)
741{
742 /*
743 * Allow sending HMRFPO ENABLE command only if:
744 * - CSE's current working state is Normal and current operation mode is Normal
745 * - (or) cse's current working state is normal and current operation mode is
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530746 * Soft Temp Disable if CSE's Firmware SKU is Lite
Sridhar Siricillad16187e2019-11-27 16:02:47 +0530747 */
748 if (!cse_is_hfs1_cws_normal())
749 return false;
750
751 if (cse_is_hfs1_com_normal())
752 return true;
753
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530754 if (cse_is_hfs3_fw_sku_lite() && cse_is_hfs1_com_soft_temp_disable())
Sridhar Siricillad16187e2019-11-27 16:02:47 +0530755 return true;
756
757 return false;
758}
759
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530760/* Sends HMRFPO Enable command to CSE */
Sridhar Siricillaad6d3122023-01-10 14:59:35 +0530761enum cb_err cse_hmrfpo_enable(void)
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530762{
763 struct hmrfpo_enable_msg {
764 struct mkhi_hdr hdr;
765 uint32_t nonce[2];
766 } __packed;
767
768 /* HMRFPO Enable message */
769 struct hmrfpo_enable_msg msg = {
770 .hdr = {
Sridhar Siricillae202e672020-01-07 23:36:40 +0530771 .group_id = MKHI_GROUP_ID_HMRFPO,
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530772 .command = MKHI_HMRFPO_ENABLE,
773 },
774 .nonce = {0},
775 };
776
777 /* HMRFPO Enable response */
778 struct hmrfpo_enable_resp {
779 struct mkhi_hdr hdr;
Sridhar Siricillae202e672020-01-07 23:36:40 +0530780 /* Base addr for factory data area, not relevant for client SKUs */
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530781 uint32_t fct_base;
Sridhar Siricillae202e672020-01-07 23:36:40 +0530782 /* Length of factory data area, not relevant for client SKUs */
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530783 uint32_t fct_limit;
784 uint8_t status;
Sridhar Siricillad16187e2019-11-27 16:02:47 +0530785 uint8_t reserved[3];
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530786 } __packed;
787
788 struct hmrfpo_enable_resp resp;
789 size_t resp_size = sizeof(struct hmrfpo_enable_resp);
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530790
Sridhar Siricilla49c25f22021-11-27 19:56:47 +0530791 if (cse_is_hfs1_com_secover_mei_msg()) {
792 printk(BIOS_DEBUG, "HECI: CSE is already in security override mode, "
793 "skip sending HMRFPO_ENABLE command to CSE\n");
Sridhar Siricillaad6d3122023-01-10 14:59:35 +0530794 return CB_SUCCESS;
Sridhar Siricilla49c25f22021-11-27 19:56:47 +0530795 }
796
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530797 printk(BIOS_DEBUG, "HECI: Send HMRFPO Enable Command\n");
Sridhar Siricillad16187e2019-11-27 16:02:47 +0530798
799 if (!cse_is_hmrfpo_enable_allowed()) {
800 printk(BIOS_ERR, "HECI: CSE does not meet required prerequisites\n");
Sridhar Siricillaad6d3122023-01-10 14:59:35 +0530801 return CB_ERR;
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530802 }
803
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530804 if (heci_send_receive(&msg, sizeof(struct hmrfpo_enable_msg),
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530805 &resp, &resp_size, HECI_MKHI_ADDR))
Sridhar Siricillaad6d3122023-01-10 14:59:35 +0530806 return CB_ERR;
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530807
808 if (resp.hdr.result) {
809 printk(BIOS_ERR, "HECI: Resp Failed:%d\n", resp.hdr.result);
Sridhar Siricillaad6d3122023-01-10 14:59:35 +0530810 return CB_ERR;
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530811 }
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530812
Sridhar Siricillad16187e2019-11-27 16:02:47 +0530813 if (resp.status) {
814 printk(BIOS_ERR, "HECI: HMRFPO_Enable Failed (resp status: %d)\n", resp.status);
Sridhar Siricillaad6d3122023-01-10 14:59:35 +0530815 return CB_ERR;
Sridhar Siricillad16187e2019-11-27 16:02:47 +0530816 }
817
Sridhar Siricillaad6d3122023-01-10 14:59:35 +0530818 return CB_SUCCESS;
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530819}
820
821/*
822 * Sends HMRFPO Get Status command to CSE to get the HMRFPO status.
Sridhar Siricilla63be9182020-01-19 12:38:56 +0530823 * The status can be DISABLED/LOCKED/ENABLED
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530824 */
Sridhar Siricillaff072e62019-11-27 14:55:16 +0530825int cse_hmrfpo_get_status(void)
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530826{
827 struct hmrfpo_get_status_msg {
828 struct mkhi_hdr hdr;
829 } __packed;
830
831 struct hmrfpo_get_status_resp {
832 struct mkhi_hdr hdr;
833 uint8_t status;
Sridhar Siricilla63be9182020-01-19 12:38:56 +0530834 uint8_t reserved[3];
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530835 } __packed;
836
837 struct hmrfpo_get_status_msg msg = {
838 .hdr = {
Sridhar Siricillae202e672020-01-07 23:36:40 +0530839 .group_id = MKHI_GROUP_ID_HMRFPO,
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530840 .command = MKHI_HMRFPO_GET_STATUS,
841 },
842 };
843 struct hmrfpo_get_status_resp resp;
844 size_t resp_size = sizeof(struct hmrfpo_get_status_resp);
845
846 printk(BIOS_INFO, "HECI: Sending Get HMRFPO Status Command\n");
847
Sridhar Siricilla206905c2020-02-06 18:48:22 +0530848 if (!cse_is_hfs1_cws_normal()) {
849 printk(BIOS_ERR, "HECI: CSE's current working state is not Normal\n");
850 return -1;
851 }
852
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530853 if (heci_send_receive(&msg, sizeof(struct hmrfpo_get_status_msg),
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530854 &resp, &resp_size, HECI_MKHI_ADDR)) {
Sridhar Siricillae30a0e62019-08-31 16:12:21 +0530855 printk(BIOS_ERR, "HECI: HMRFPO send/receive fail\n");
856 return -1;
857 }
858
859 if (resp.hdr.result) {
860 printk(BIOS_ERR, "HECI: HMRFPO Resp Failed:%d\n",
861 resp.hdr.result);
862 return -1;
863 }
864
865 return resp.status;
866}
867
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530868void print_me_fw_version(void *unused)
869{
Johnny Lin72e76672021-10-09 12:35:35 +0800870 struct me_fw_ver_resp resp = {0};
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530871
872 /* Ignore if UART debugging is disabled */
873 if (!CONFIG(CONSOLE_SERIAL))
874 return;
875
Johnny Lin72e76672021-10-09 12:35:35 +0800876 if (get_me_fw_version(&resp) == CB_SUCCESS) {
877 printk(BIOS_DEBUG, "ME: Version: %d.%d.%d.%d\n", resp.code.major,
878 resp.code.minor, resp.code.hotfix, resp.code.build);
879 return;
880 }
881 printk(BIOS_DEBUG, "ME: Version: Unavailable\n");
882}
883
884enum cb_err get_me_fw_version(struct me_fw_ver_resp *resp)
885{
886 const struct mkhi_hdr fw_ver_msg = {
887 .group_id = MKHI_GROUP_ID_GEN,
888 .command = MKHI_GEN_GET_FW_VERSION,
889 };
890
891 if (resp == NULL) {
892 printk(BIOS_ERR, "%s failed, null pointer parameter\n", __func__);
893 return CB_ERR;
894 }
895 size_t resp_size = sizeof(*resp);
896
Wim Vervoorn8602fb72020-03-30 12:17:54 +0200897 /* Ignore if CSE is disabled */
898 if (!is_cse_enabled())
Johnny Lin72e76672021-10-09 12:35:35 +0800899 return CB_ERR;
Wim Vervoorn8602fb72020-03-30 12:17:54 +0200900
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530901 /*
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530902 * Ignore if ME Firmware SKU type is Lite since
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530903 * print_boot_partition_info() logs RO(BP1) and RW(BP2) versions.
904 */
Sridhar Siricilla99dbca32020-05-12 21:05:04 +0530905 if (cse_is_hfs3_fw_sku_lite())
Johnny Lin72e76672021-10-09 12:35:35 +0800906 return CB_ERR;
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530907
908 /*
909 * Prerequisites:
910 * 1) HFSTS1 Current Working State is Normal
911 * 2) HFSTS1 Current Operation Mode is Normal
912 * 3) It's after DRAM INIT DONE message (taken care of by calling it
913 * during ramstage
914 */
915 if (!cse_is_hfs1_cws_normal() || !cse_is_hfs1_com_normal())
Johnny Lin72e76672021-10-09 12:35:35 +0800916 return CB_ERR;
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530917
918 heci_reset();
919
Sridhar Siricilla6836da22022-02-23 23:36:45 +0530920 if (heci_send_receive(&fw_ver_msg, sizeof(fw_ver_msg), resp, &resp_size,
Rizwan Qureshi957857d2021-08-30 16:43:57 +0530921 HECI_MKHI_ADDR))
Johnny Lin72e76672021-10-09 12:35:35 +0800922 return CB_ERR;
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530923
Johnny Lin72e76672021-10-09 12:35:35 +0800924 if (resp->hdr.result)
925 return CB_ERR;
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530926
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530927
Johnny Lin72e76672021-10-09 12:35:35 +0800928 return CB_SUCCESS;
Sridhar Siricilla24a974a2020-02-19 14:41:36 +0530929}
930
Tim Wawrzynczak09635f42021-06-18 10:08:47 -0600931void cse_trigger_vboot_recovery(enum csme_failure_reason reason)
932{
933 printk(BIOS_DEBUG, "cse: CSE status registers: HFSTS1: 0x%x, HFSTS2: 0x%x "
934 "HFSTS3: 0x%x\n", me_read_config32(PCI_ME_HFSTS1),
935 me_read_config32(PCI_ME_HFSTS2), me_read_config32(PCI_ME_HFSTS3));
936
Jakub Czapiga605f7932022-11-04 12:18:04 +0000937 if (CONFIG(VBOOT))
938 vboot_fail_and_reboot(vboot_get_context(), VB2_RECOVERY_INTEL_CSE_LITE_SKU,
939 reason);
940
Tim Wawrzynczak09635f42021-06-18 10:08:47 -0600941 die("cse: Failed to trigger recovery mode(recovery subcode:%d)\n", reason);
942}
943
Subrata Banikc6e25522021-09-30 18:14:09 +0530944static bool disable_cse_idle(pci_devfn_t dev)
Subrata Banika219edb2021-09-25 15:02:37 +0530945{
946 struct stopwatch sw;
Subrata Banikc6e25522021-09-30 18:14:09 +0530947 uint32_t dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE);
Subrata Banika219edb2021-09-25 15:02:37 +0530948 dev_idle_ctrl &= ~CSE_DEV_IDLE;
Subrata Banikc6e25522021-09-30 18:14:09 +0530949 write_bar(dev, MMIO_CSE_DEVIDLE, dev_idle_ctrl);
Subrata Banika219edb2021-09-25 15:02:37 +0530950
Subrata Banik03aef282021-09-28 18:10:24 +0530951 stopwatch_init_usecs_expire(&sw, HECI_CIP_TIMEOUT_US);
Subrata Banika219edb2021-09-25 15:02:37 +0530952 do {
Subrata Banikc6e25522021-09-30 18:14:09 +0530953 dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE);
Subrata Banika219edb2021-09-25 15:02:37 +0530954 if ((dev_idle_ctrl & CSE_DEV_CIP) == CSE_DEV_CIP)
955 return true;
Subrata Banik03aef282021-09-28 18:10:24 +0530956 udelay(HECI_DELAY_US);
Subrata Banika219edb2021-09-25 15:02:37 +0530957 } while (!stopwatch_expired(&sw));
958
959 return false;
960}
961
Subrata Banikc6e25522021-09-30 18:14:09 +0530962static void enable_cse_idle(pci_devfn_t dev)
Subrata Banika219edb2021-09-25 15:02:37 +0530963{
Subrata Banikc6e25522021-09-30 18:14:09 +0530964 uint32_t dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE);
Subrata Banika219edb2021-09-25 15:02:37 +0530965 dev_idle_ctrl |= CSE_DEV_IDLE;
Subrata Banikc6e25522021-09-30 18:14:09 +0530966 write_bar(dev, MMIO_CSE_DEVIDLE, dev_idle_ctrl);
Subrata Banika219edb2021-09-25 15:02:37 +0530967}
968
Subrata Banikc6e25522021-09-30 18:14:09 +0530969enum cse_device_state get_cse_device_state(unsigned int devfn)
Subrata Banika219edb2021-09-25 15:02:37 +0530970{
Subrata Banikc6e25522021-09-30 18:14:09 +0530971 pci_devfn_t dev = PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn));
972 uint32_t dev_idle_ctrl = read_bar(dev, MMIO_CSE_DEVIDLE);
Subrata Banika219edb2021-09-25 15:02:37 +0530973 if ((dev_idle_ctrl & CSE_DEV_IDLE) == CSE_DEV_IDLE)
974 return DEV_IDLE;
975
976 return DEV_ACTIVE;
977}
978
Subrata Banikc6e25522021-09-30 18:14:09 +0530979static enum cse_device_state ensure_cse_active(pci_devfn_t dev)
Subrata Banika219edb2021-09-25 15:02:37 +0530980{
Subrata Banikc6e25522021-09-30 18:14:09 +0530981 if (!disable_cse_idle(dev))
Subrata Banika219edb2021-09-25 15:02:37 +0530982 return DEV_IDLE;
Subrata Banikc6e25522021-09-30 18:14:09 +0530983 pci_or_config32(dev, PCI_COMMAND, PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Subrata Banika219edb2021-09-25 15:02:37 +0530984
985 return DEV_ACTIVE;
986}
987
Subrata Banikc6e25522021-09-30 18:14:09 +0530988static void ensure_cse_idle(pci_devfn_t dev)
Subrata Banika219edb2021-09-25 15:02:37 +0530989{
Subrata Banikc6e25522021-09-30 18:14:09 +0530990 enable_cse_idle(dev);
Subrata Banika219edb2021-09-25 15:02:37 +0530991
Subrata Banikc6e25522021-09-30 18:14:09 +0530992 pci_and_config32(dev, PCI_COMMAND, ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER));
Subrata Banika219edb2021-09-25 15:02:37 +0530993}
994
Subrata Banikc6e25522021-09-30 18:14:09 +0530995bool set_cse_device_state(unsigned int devfn, enum cse_device_state requested_state)
Subrata Banika219edb2021-09-25 15:02:37 +0530996{
Subrata Banikc6e25522021-09-30 18:14:09 +0530997 enum cse_device_state current_state = get_cse_device_state(devfn);
998 pci_devfn_t dev = PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn));
Subrata Banika219edb2021-09-25 15:02:37 +0530999
1000 if (current_state == requested_state)
1001 return true;
1002
1003 if (requested_state == DEV_ACTIVE)
Subrata Banikc6e25522021-09-30 18:14:09 +05301004 return ensure_cse_active(dev) == requested_state;
Subrata Banika219edb2021-09-25 15:02:37 +05301005 else
Subrata Banikc6e25522021-09-30 18:14:09 +05301006 ensure_cse_idle(dev);
Subrata Banika219edb2021-09-25 15:02:37 +05301007
1008 return true;
1009}
1010
Subrata Banik526cc3e2022-01-31 21:55:51 +05301011void cse_set_to_d0i3(void)
1012{
1013 if (!is_cse_devfn_visible(PCH_DEVFN_CSE))
1014 return;
1015
1016 set_cse_device_state(PCH_DEVFN_CSE, DEV_IDLE);
1017}
1018
1019/* Function to set D0I3 for all HECI devices */
1020void heci_set_to_d0i3(void)
1021{
1022 for (int i = 0; i < CONFIG_MAX_HECI_DEVICES; i++) {
Subrata Banik57909562022-06-02 00:25:36 +05301023 unsigned int devfn = PCI_DEVFN(PCH_DEV_SLOT_CSE, i);
Subrata Banik01bf0022022-04-06 18:59:37 +05301024 if (!is_cse_devfn_visible(devfn))
Subrata Banik526cc3e2022-01-31 21:55:51 +05301025 continue;
1026
Subrata Banik01bf0022022-04-06 18:59:37 +05301027 set_cse_device_state(devfn, DEV_IDLE);
Subrata Banik526cc3e2022-01-31 21:55:51 +05301028 }
1029}
1030
Subrata Banik801dbf42022-06-01 07:56:40 +00001031/* Initialize the HECI devices. */
1032void heci_init(void)
1033{
1034 for (int i = 0; i < CONFIG_MAX_HECI_DEVICES; i++) {
1035 unsigned int devfn = PCI_DEVFN(PCH_DEV_SLOT_CSE, i);
1036 pci_devfn_t dev = PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn));
1037
1038 if (!is_cse_devfn_visible(devfn))
1039 continue;
1040
1041 /* Assume it is already initialized, nothing else to do */
1042 if (get_cse_bar(dev))
1043 return;
1044
1045 heci_assign_resource(dev, HECI1_BASE_ADDRESS + (i * HECI_BASE_SIZE));
1046
1047 ensure_cse_active(dev);
1048 }
1049 /* Trigger HECI Reset and make Host ready for communication with CSE */
1050 heci_reset();
1051}
1052
Subrata Banik80c92892022-02-01 00:26:55 +05301053void cse_control_global_reset_lock(void)
1054{
1055 /*
1056 * As per ME BWG recommendation the BIOS should not lock down CF9GR bit during
1057 * manufacturing and re-manufacturing environment if HFSTS1 [4] is set. Note:
1058 * this recommendation is not applicable for CSE-Lite SKUs where BIOS should set
1059 * CF9LOCK bit irrespectively.
1060 *
1061 * Other than that, make sure payload/OS can't trigger global reset.
1062 *
1063 * BIOS must also ensure that CF9GR is cleared and locked (Bit31 of ETR3)
1064 * prior to transferring control to the OS.
1065 */
1066 if (CONFIG(SOC_INTEL_CSE_LITE_SKU) || cse_is_hfs1_spi_protected())
1067 pmc_global_reset_disable_and_lock();
1068 else
1069 pmc_global_reset_enable(false);
1070}
1071
Andrey Petrov04a72c42017-03-01 15:51:57 -08001072#if ENV_RAMSTAGE
1073
Sean Rhodes69ed3ed2021-04-30 16:38:17 +01001074/*
1075 * Disable the Intel (CS)Management Engine via HECI based on a cmos value
1076 * of `me_state`. A value of `0` will result in a (CS)ME state of `0` (working)
1077 * and value of `1` will result in a (CS)ME state of `3` (disabled).
1078 *
1079 * It isn't advised to use this in combination with me_cleaner.
1080 *
1081 * It is advisable to have a second cmos option called `me_state_counter`.
1082 * Whilst not essential, it avoid reboots loops if the (CS)ME fails to
1083 * change states after 3 attempts. Some versions of the (CS)ME need to be
1084 * reset 3 times.
1085 *
1086 * Ideal cmos values would be:
1087 *
1088 * # coreboot config options: cpu
1089 * 432 1 e 5 me_state
1090 * 440 4 h 0 me_state_counter
1091 *
1092 * #ID value text
1093 * 5 0 Enable
1094 * 5 1 Disable
1095 */
1096
1097static void me_reset_with_count(void)
1098{
1099 unsigned int cmos_me_state_counter = get_uint_option("me_state_counter", UINT_MAX);
1100
1101 if (cmos_me_state_counter != UINT_MAX) {
1102 printk(BIOS_DEBUG, "CMOS: me_state_counter = %u\n", cmos_me_state_counter);
1103 /* Avoid boot loops by only trying a state change 3 times */
1104 if (cmos_me_state_counter < ME_DISABLE_ATTEMPTS) {
1105 cmos_me_state_counter++;
1106 set_uint_option("me_state_counter", cmos_me_state_counter);
1107 printk(BIOS_DEBUG, "ME: Reset attempt %u/%u.\n", cmos_me_state_counter,
1108 ME_DISABLE_ATTEMPTS);
1109 do_global_reset();
1110 } else {
1111 /*
1112 * If the (CS)ME fails to change states after 3 attempts, it will
1113 * likely need a cold boot, or recovering.
1114 */
Julius Wernere9665952022-01-21 17:06:20 -08001115 printk(BIOS_ERR, "Failed to change ME state in %u attempts!\n",
Sean Rhodes69ed3ed2021-04-30 16:38:17 +01001116 ME_DISABLE_ATTEMPTS);
1117
1118 }
1119 } else {
1120 printk(BIOS_DEBUG, "ME: Resetting");
1121 do_global_reset();
1122 }
1123}
1124
1125static void cse_set_state(struct device *dev)
1126{
1127
1128 /* (CS)ME Disable Command */
1129 struct me_disable_command {
1130 struct mkhi_hdr hdr;
1131 uint32_t rule_id;
1132 uint8_t rule_len;
1133 uint32_t rule_data;
1134 } __packed me_disable = {
1135 .hdr = {
1136 .group_id = MKHI_GROUP_ID_FWCAPS,
1137 .command = MKHI_SET_ME_DISABLE,
1138 },
1139 .rule_id = ME_DISABLE_RULE_ID,
1140 .rule_len = ME_DISABLE_RULE_LENGTH,
1141 .rule_data = ME_DISABLE_COMMAND,
1142 };
1143
1144 struct me_disable_reply {
1145 struct mkhi_hdr hdr;
1146 uint32_t rule_id;
1147 } __packed;
1148
1149 struct me_disable_reply disable_reply;
1150
1151 size_t disable_reply_size;
1152
1153 /* (CS)ME Enable Command */
1154 struct me_enable_command {
1155 struct mkhi_hdr hdr;
1156 } me_enable = {
1157 .hdr = {
1158 .group_id = MKHI_GROUP_ID_BUP_COMMON,
1159 .command = MKHI_SET_ME_ENABLE,
1160 },
1161 };
1162
1163 struct me_enable_reply {
1164 struct mkhi_hdr hdr;
1165 } __packed;
1166
1167 struct me_enable_reply enable_reply;
1168
1169 size_t enable_reply_size;
1170
1171 /* Function Start */
1172
1173 int send;
1174 int result;
1175 /*
1176 * Check if the CMOS value "me_state" exists, if it doesn't, then
1177 * don't do anything.
1178 */
1179 const unsigned int cmos_me_state = get_uint_option("me_state", UINT_MAX);
1180
1181 if (cmos_me_state == UINT_MAX)
1182 return;
1183
1184 printk(BIOS_DEBUG, "CMOS: me_state = %u\n", cmos_me_state);
1185
1186 /*
1187 * We only take action if the me_state doesn't match the CS(ME) working state
1188 */
1189
1190 const unsigned int soft_temp_disable = cse_is_hfs1_com_soft_temp_disable();
1191
1192 if (cmos_me_state && !soft_temp_disable) {
1193 /* me_state should be disabled, but it's enabled */
1194 printk(BIOS_DEBUG, "ME needs to be disabled.\n");
1195 send = heci_send_receive(&me_disable, sizeof(me_disable),
1196 &disable_reply, &disable_reply_size, HECI_MKHI_ADDR);
1197 result = disable_reply.hdr.result;
1198 } else if (!cmos_me_state && soft_temp_disable) {
1199 /* me_state should be enabled, but it's disabled */
1200 printk(BIOS_DEBUG, "ME needs to be enabled.\n");
1201 send = heci_send_receive(&me_enable, sizeof(me_enable),
1202 &enable_reply, &enable_reply_size, HECI_MKHI_ADDR);
1203 result = enable_reply.hdr.result;
1204 } else {
1205 printk(BIOS_DEBUG, "ME is %s.\n", cmos_me_state ? "disabled" : "enabled");
1206 unsigned int cmos_me_state_counter = get_uint_option("me_state_counter",
1207 UINT_MAX);
1208 /* set me_state_counter to 0 */
1209 if ((cmos_me_state_counter != UINT_MAX && cmos_me_state_counter != 0))
1210 set_uint_option("me_state_counter", 0);
1211 return;
1212 }
1213
1214 printk(BIOS_DEBUG, "HECI: ME state change send %s!\n",
Sridhar Siricilla6836da22022-02-23 23:36:45 +05301215 !send ? "success" : "failure");
Sean Rhodes69ed3ed2021-04-30 16:38:17 +01001216 printk(BIOS_DEBUG, "HECI: ME state change result %s!\n",
1217 result ? "success" : "failure");
1218
1219 /*
1220 * Reset if the result was successful, or if the send failed as some older
1221 * version of the Intel (CS)ME won't successfully receive the message unless reset
1222 * twice.
1223 */
1224 if (send || !result)
1225 me_reset_with_count();
1226}
1227
Subrata Banik90e318b2022-02-06 16:26:45 +05301228/*
1229 * `cse_final_ready_to_boot` function is native implementation of equivalent events
1230 * performed by FSP NotifyPhase(Ready To Boot) API invocations.
1231 *
1232 * Operations are:
Subrata Banik5214c402022-11-24 20:43:37 +05301233 * 1. Perform global reset lock.
1234 * 2. Put HECI1 to D0i3 and disable the HECI1 if the user selects
Subrata Banik670572f2022-04-25 15:39:55 +05301235 * DISABLE_HECI1_AT_PRE_BOOT config or CSE HFSTS1 Operation Mode is
1236 * `Software Temporary Disable`.
Subrata Banik90e318b2022-02-06 16:26:45 +05301237 */
1238static void cse_final_ready_to_boot(void)
1239{
Subrata Banik90e318b2022-02-06 16:26:45 +05301240 cse_control_global_reset_lock();
1241
Subrata Banik670572f2022-04-25 15:39:55 +05301242 if (CONFIG(DISABLE_HECI1_AT_PRE_BOOT) || cse_is_hfs1_com_soft_temp_disable()) {
Subrata Banik90e318b2022-02-06 16:26:45 +05301243 cse_set_to_d0i3();
1244 heci1_disable();
1245 }
1246}
1247
1248/*
1249 * `cse_final_end_of_firmware` function is native implementation of equivalent events
1250 * performed by FSP NotifyPhase(End of Firmware) API invocations.
1251 *
1252 * Operations are:
1253 * 1. Set D0I3 for all HECI devices.
1254 */
1255static void cse_final_end_of_firmware(void)
1256{
1257 heci_set_to_d0i3();
1258}
1259
Subrata Banik90e318b2022-02-06 16:26:45 +05301260/*
Subrata Banik17a3da82022-11-24 21:51:42 +05301261 * This function to perform essential post EOP cse related operations
1262 * upon SoC selecting `SOC_INTEL_CSE_SEND_EOP_LATE` config
1263 */
1264void cse_late_finalize(void)
1265{
1266 if (!CONFIG(SOC_INTEL_CSE_SEND_EOP_LATE))
1267 return;
1268
1269 if (!CONFIG(USE_FSP_NOTIFY_PHASE_READY_TO_BOOT))
1270 cse_final_ready_to_boot();
1271
1272 if (!CONFIG(USE_FSP_NOTIFY_PHASE_END_OF_FIRMWARE))
1273 cse_final_end_of_firmware();
1274}
1275
1276/*
Subrata Banik90e318b2022-02-06 16:26:45 +05301277 * `cse_final` function is native implementation of equivalent events performed by
1278 * each FSP NotifyPhase() API invocations.
1279 */
1280static void cse_final(struct device *dev)
1281{
Subrata Banik5214c402022-11-24 20:43:37 +05301282 /* SoC user decided to send EOP late */
1283 if (CONFIG(SOC_INTEL_CSE_SEND_EOP_LATE))
1284 return;
1285
1286 /* 1. Send EOP to CSE if not done.*/
1287 if (CONFIG(SOC_INTEL_CSE_SET_EOP))
1288 cse_send_end_of_post();
1289
Angel Pons28315f82022-04-19 10:03:56 +02001290 if (!CONFIG(USE_FSP_NOTIFY_PHASE_READY_TO_BOOT))
1291 cse_final_ready_to_boot();
1292
1293 if (!CONFIG(USE_FSP_NOTIFY_PHASE_END_OF_FIRMWARE))
1294 cse_final_end_of_firmware();
Subrata Banik90e318b2022-02-06 16:26:45 +05301295}
1296
Nico Huber57686192022-08-06 19:11:55 +02001297struct device_operations cse_ops = {
Subrata Banik38abbda2021-09-30 13:15:50 +05301298 .set_resources = pci_dev_set_resources,
Andrey Petrov04a72c42017-03-01 15:51:57 -08001299 .read_resources = pci_dev_read_resources,
1300 .enable_resources = pci_dev_enable_resources,
1301 .init = pci_dev_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +05301302 .ops_pci = &pci_dev_ops_pci,
Sean Rhodes69ed3ed2021-04-30 16:38:17 +01001303 .enable = cse_set_state,
Subrata Banik90e318b2022-02-06 16:26:45 +05301304 .final = cse_final,
Andrey Petrov04a72c42017-03-01 15:51:57 -08001305};
1306
Hannah Williams63142152017-06-12 14:03:18 -07001307static const unsigned short pci_device_ids[] = {
Wonkyu Kim9f401072020-11-13 15:16:32 -08001308 PCI_DID_INTEL_MTL_CSE0,
Felix Singer43b7f412022-03-07 04:34:52 +01001309 PCI_DID_INTEL_APL_CSE0,
1310 PCI_DID_INTEL_GLK_CSE0,
1311 PCI_DID_INTEL_CNL_CSE0,
Felix Singer43b7f412022-03-07 04:34:52 +01001312 PCI_DID_INTEL_LWB_CSE0,
1313 PCI_DID_INTEL_LWB_CSE0_SUPER,
1314 PCI_DID_INTEL_CNP_H_CSE0,
Felix Singer43b7f412022-03-07 04:34:52 +01001315 PCI_DID_INTEL_CMP_CSE0,
1316 PCI_DID_INTEL_CMP_H_CSE0,
1317 PCI_DID_INTEL_TGL_CSE0,
1318 PCI_DID_INTEL_TGL_H_CSE0,
1319 PCI_DID_INTEL_MCC_CSE0,
1320 PCI_DID_INTEL_MCC_CSE1,
1321 PCI_DID_INTEL_MCC_CSE2,
1322 PCI_DID_INTEL_MCC_CSE3,
1323 PCI_DID_INTEL_JSP_CSE0,
1324 PCI_DID_INTEL_JSP_CSE1,
1325 PCI_DID_INTEL_JSP_CSE2,
1326 PCI_DID_INTEL_JSP_CSE3,
1327 PCI_DID_INTEL_ADP_P_CSE0,
1328 PCI_DID_INTEL_ADP_P_CSE1,
1329 PCI_DID_INTEL_ADP_P_CSE2,
1330 PCI_DID_INTEL_ADP_P_CSE3,
1331 PCI_DID_INTEL_ADP_S_CSE0,
1332 PCI_DID_INTEL_ADP_S_CSE1,
1333 PCI_DID_INTEL_ADP_S_CSE2,
1334 PCI_DID_INTEL_ADP_S_CSE3,
1335 PCI_DID_INTEL_ADP_M_CSE0,
1336 PCI_DID_INTEL_ADP_M_CSE1,
1337 PCI_DID_INTEL_ADP_M_CSE2,
1338 PCI_DID_INTEL_ADP_M_CSE3,
Hannah Williams63142152017-06-12 14:03:18 -07001339 0,
1340};
1341
Andrey Petrov04a72c42017-03-01 15:51:57 -08001342static const struct pci_driver cse_driver __pci_driver = {
1343 .ops = &cse_ops,
Felix Singer43b7f412022-03-07 04:34:52 +01001344 .vendor = PCI_VID_INTEL,
Andrey Petrov04a72c42017-03-01 15:51:57 -08001345 /* SoC/chipset needs to provide PCI device ID */
Andrey Petrov0405de92017-06-05 13:25:29 -07001346 .devices = pci_device_ids
Andrey Petrov04a72c42017-03-01 15:51:57 -08001347};
1348
1349#endif