xref: /aosp_15_r20/external/coreboot/src/soc/intel/common/basecode/debug/debug_feature.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <intelbasecode/debug_feature.h>
4 #include <console/console.h>
5 #include <spi_flash.h>
6 
7 #define SI_DESC_OEM_SECTION_OFFSET	0xF00
8 #define DEBUG_FEATURE_CTRL_OFFSET	SI_DESC_OEM_SECTION_OFFSET
9 #define DEBUG_FEATURE_CTRL_SZ		64
10 #define SI_DESC_REGION_SZ		4096
11 
12 #define DEBUG_FEATURE_UNDEFINED		0xff
13 struct debug_feature_cntrl {
14 	uint8_t cse_fw_update_disable; /* Byte location: 0xF00 */
15 
16 	/*
17 	 * Supported CPU Trace Hub modes:
18 	 * 0: Disable, 1: Target Debugger Mode, 2: Host Debugger Mode
19 	 */
20 	uint8_t cpu_tracehub_mode;     /* Byte location: 0xF01 */
21 
22 	/*
23 	 * Supported PCH Trace Hub modes:
24 	 * 0: Disable, 1:Target Debugger Mode, 2:Host Debugger Mode
25 	 */
26 	uint8_t pch_tracehub_mode;     /* Byte location: 0xF02 */
27 	uint8_t reserved[61];
28 };
29 
30 static struct debug_feature_cntrl dbg_feature_cntrl;
31 
32 _Static_assert(sizeof(struct debug_feature_cntrl) % 64 == 0
33 		&& sizeof(struct debug_feature_cntrl) <= 256,
34 		"sizeof(struct debug_feature_cntrl) must be a multiple of 64 bytes and up to 256 bytes");
35 
debug_get_pch_cpu_tracehub_modes(uint8_t * cpu_tracehub_mode,uint8_t * pch_tracehub_mode)36 void debug_get_pch_cpu_tracehub_modes(uint8_t *cpu_tracehub_mode, uint8_t *pch_tracehub_mode)
37 {
38 	if (dbg_feature_cntrl.pch_tracehub_mode != DEBUG_FEATURE_UNDEFINED)
39 		*pch_tracehub_mode = dbg_feature_cntrl.pch_tracehub_mode;
40 
41 	if (dbg_feature_cntrl.cpu_tracehub_mode != DEBUG_FEATURE_UNDEFINED)
42 		*cpu_tracehub_mode = dbg_feature_cntrl.cpu_tracehub_mode;
43 
44 	printk(BIOS_DEBUG, "rt_debug: CPU Trace Hub Mode: %d PCH Trace Hub Mode: %d\n",
45 			*pch_tracehub_mode, *cpu_tracehub_mode);
46 }
47 
is_debug_cse_fw_update_disable(void)48 bool is_debug_cse_fw_update_disable(void)
49 {
50 	printk(BIOS_DEBUG, "rt_debug: dbg_feature_cntrl.cse_fw_update_disable=%d\n",
51 			dbg_feature_cntrl.cse_fw_update_disable);
52 
53 	return dbg_feature_cntrl.cse_fw_update_disable == 1;
54 }
55 
dbg_feature_cntrl_init(void)56 enum cb_err dbg_feature_cntrl_init(void)
57 {
58 	const struct spi_flash *spi_flash_dev = boot_device_spi_flash();
59 
60 	if (spi_flash_dev == NULL) {
61 		printk(BIOS_ERR, "Failed to Initialize boot device SPI flash\n");
62 		return CB_ERR;
63 	}
64 
65 	if (spi_flash_read(spi_flash_dev, DEBUG_FEATURE_CTRL_OFFSET,
66 				DEBUG_FEATURE_CTRL_SZ, &dbg_feature_cntrl)) {
67 		printk(BIOS_ERR, "Failed to read Descriptor Region from SPI Flash\n");
68 		return CB_ERR;
69 	}
70 	return CB_SUCCESS;
71 }
72