summaryrefslogtreecommitdiffstats
path: root/src/drivers/intel/fsp2_0/debug.c
blob: 130ea6d66d7a919cfff45c70e7694b3b8d02d35a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include <commonlib/helpers.h>
#include <console/console.h>
#include <console/streams.h>
#include <cpu/x86/mtrr.h>
#include <fsp/debug.h>
#include <fsp/util.h>

asmlinkage size_t fsp_write_line(uint8_t *buffer, size_t number_of_bytes)
{
	console_write_line(buffer, number_of_bytes);
	return number_of_bytes;
}

enum fsp_call_phase {
	BEFORE_FSP_CALL,
	AFTER_FSP_CALL,
};

static void fsp_gpio_config_check(enum fsp_call_phase phase, const char *call_str)
{
	switch (phase) {
	case BEFORE_FSP_CALL:
		printk(BIOS_SPEW, "Snapshot all GPIOs before %s.\n", call_str);
		gpio_snapshot();
		break;
	case AFTER_FSP_CALL:
		printk(BIOS_SPEW, "Verify GPIO snapshot after %s...", call_str);
		printk(BIOS_SPEW, "%zd changes detected!\n", gpio_verify_snapshot());
		break;
	default:
		break;
	}
}

enum fsp_log_level fsp_map_console_log_level(void)
{
	enum fsp_log_level fsp_debug_level;

	switch (get_log_level()) {
	case BIOS_EMERG:
	case BIOS_ALERT:
	case BIOS_CRIT:
	case BIOS_ERR:
		fsp_debug_level = FSP_LOG_LEVEL_ERR;
		break;
	case BIOS_WARNING:
		fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN;
		break;
	case BIOS_NOTICE:
		fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO;
		break;
	case BIOS_INFO:
		fsp_debug_level = FSP_LOG_LEVEL_ERR_WARN_INFO_EVENT;
		break;
	case BIOS_DEBUG:
	case BIOS_SPEW:
		fsp_debug_level = FSP_LOG_LEVEL_VERBOSE;
		break;
	default:
		fsp_debug_level = FSP_LOG_LEVEL_DISABLE;
		break;
	}

	if (!CONFIG(DEBUG_RAM_SETUP))
		fsp_debug_level = MIN(fsp_debug_level, FSP_LOG_LEVEL_ERR_WARN);

	return fsp_debug_level;
}

/*-----------
 * MemoryInit
 *-----------
 */
void fsp_debug_before_memory_init(fsp_memory_init_fn memory_init,
	const FSPM_UPD *fspm_old_upd,
	const FSPM_UPD *fspm_new_upd)
{
	display_mtrrs();

	/* Display the UPD values */
	if (CONFIG(DISPLAY_UPD_DATA))
		fspm_display_upd_values(fspm_old_upd, fspm_new_upd);

	/* Display the call entry point and parameters */
	if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
		return;
	printk(BIOS_SPEW, "Calling FspMemoryInit: %p\n", memory_init);
	printk(BIOS_SPEW, "\t%p: raminit_upd\n", fspm_new_upd);
	printk(BIOS_SPEW, "\t%p: &hob_list_ptr\n", fsp_get_hob_list_ptr());
}

void fsp_debug_after_memory_init(uint32_t status)
{
	if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
		printk(BIOS_SPEW, "FspMemoryInit returned 0x%08x\n", status);

	if (status != FSP_SUCCESS)
		return;

	/* Verify that the HOB list pointer was set */
	if (fsp_get_hob_list() == NULL)
		die("ERROR - HOB list pointer was not returned!\n");

	/* Display and verify the HOBs */
	if (CONFIG(DISPLAY_HOBS))
		fsp_display_hobs();
	if (CONFIG(VERIFY_HOBS))
		fsp_verify_memory_init_hobs();

	display_mtrrs();
}

/*-----------
 * SiliconInit
 *-----------
 */
void fsp_debug_before_silicon_init(fsp_silicon_init_fn silicon_init,
	const FSPS_UPD *fsps_old_upd,
	const FSPS_UPD *fsps_new_upd)
{
	if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
		fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Silicon Init");

	display_mtrrs();

	/* Display the UPD values */
	if (CONFIG(DISPLAY_UPD_DATA))
		soc_display_fsps_upd_params(fsps_old_upd, fsps_new_upd);

	/* Display the call to FSP SiliconInit */
	if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
		return;
	printk(BIOS_SPEW, "Calling FspSiliconInit: %p\n", silicon_init);
	printk(BIOS_SPEW, "\t%p: upd\n", fsps_new_upd);
}

void fsp_debug_after_silicon_init(uint32_t status)
{
	if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
		fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Silicon Init");

	if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
		printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status);

	/* Display the HOBs */
	if (CONFIG(DISPLAY_HOBS))
		fsp_display_hobs();

	display_mtrrs();
}

/*-----------
 * FspNotify
 *-----------
 */
void fsp_before_debug_notify(fsp_notify_fn notify,
	const struct fsp_notify_params *notify_params)
{
	if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
		fsp_gpio_config_check(BEFORE_FSP_CALL, "FSP Notify");

	/* Display the call to FspNotify */
	if (!CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
		return;
	printk(BIOS_SPEW, "0x%08x: notify_params->phase\n",
		notify_params->phase);
	printk(BIOS_SPEW, "Calling FspNotify: %p\n", notify);
	printk(BIOS_SPEW, "\t%p: notify_params\n", notify_params);
}

void fsp_debug_after_notify(uint32_t status)
{
	if (CONFIG(CHECK_GPIO_CONFIG_CHANGES))
		fsp_gpio_config_check(AFTER_FSP_CALL, "FSP Notify");

	if (CONFIG(DISPLAY_FSP_CALLS_AND_STATUS))
		printk(BIOS_SPEW, "FspNotify returned 0x%08x\n", status);

	/* Display the HOBs */
	if (CONFIG(DISPLAY_HOBS))
		fsp_display_hobs();

	display_mtrrs();
}