summaryrefslogtreecommitdiff
path: root/src/soc/intel/xeon_sp/smihandler.c
blob: cb8658f69474aa69e114e64fae8a8a4c00de135c (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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <arch/io.h>
#include <console/console.h>
#include <console/uart.h>
#include <cpu/x86/smm.h>
#include <device/pci.h>
#include <drivers/uart/uart8250reg.h>
#include <intelblocks/smihandler.h>
#include <soc/pci_devs.h>
#include <soc/pm.h>

struct uart8250_state {
	uint8_t IER, IIR, MCR, LCR, DLL, DLM;
};

static struct uart8250_state s_uart8250_state;

static void uart8250_store(unsigned int base_port)
{
	/* Save previous state for restoring later. */
	s_uart8250_state.IER = inb(base_port + UART8250_IER);
	s_uart8250_state.IIR = inb(base_port + UART8250_FCR);
	s_uart8250_state.MCR = inb(base_port + UART8250_MCR);
	s_uart8250_state.LCR = inb(base_port + UART8250_LCR);
	s_uart8250_state.DLL = inb(base_port + UART8250_DLL);
	s_uart8250_state.DLM = inb(base_port + UART8250_DLM);
}

void smm_soc_early_init(void)
{
	if (CONFIG(DRIVERS_UART_8250IO) && CONFIG(DEBUG_SMI))
		uart8250_store(uart_platform_base(CONFIG_UART_FOR_CONSOLE));
}

static void uart8250_restore(unsigned int base_port)
{
	outb(s_uart8250_state.DLL, base_port + UART8250_DLL);
	outb(s_uart8250_state.DLM, base_port + UART8250_DLM);
	outb(s_uart8250_state.MCR, base_port + UART8250_MCR);
	outb(s_uart8250_state.LCR, base_port + UART8250_LCR);
	if ((s_uart8250_state.IIR & UART8250_IIR_FIFO_EN) == UART8250_IIR_FIFO_EN)
		outb(UART8250_FCR_FIFO_EN, base_port + UART8250_FCR);
	outb(s_uart8250_state.IER, base_port + UART8250_IER);
}

void smm_soc_exit(void)
{
	if (CONFIG(DRIVERS_UART_8250IO) && CONFIG(DEBUG_SMI))
		uart8250_restore(uart_platform_base(CONFIG_UART_FOR_CONSOLE));
}

/*
 * Specific SOC SMI handler during ramstage finalize phase
 */
void smihandler_soc_at_finalize(void)
{
	/* SMM_FEATURE_CONTROL can only be written within SMM. */
	printk(BIOS_DEBUG, "Lock SMM_FEATURE_CONTROL\n");
	pci_devfn_t pcie_offset = soc_get_ubox_pmon_dev();
	if (!pcie_offset) {
		printk(BIOS_ERR, "UBOX PMON is not found, cannot lock SMM_FEATURE_CONTROL!\n");
		return;
	}

	u32 val;
	val = pci_s_read_config32(pcie_offset, SMM_FEATURE_CONTROL);
	val |= (SMM_CODE_CHK_EN | SMM_FEATURE_CONTROL_LOCK);
	pci_s_write_config32(pcie_offset, SMM_FEATURE_CONTROL, val);
}

/*
 * This is the generic entry for SOC SMIs
 */
void cpu_smi_handler(void)
{

}

/* This is needed by common SMM code */
const smi_handler_t southbridge_smi[SMI_STS_BITS] = {
	[APM_STS_BIT] = smihandler_southbridge_apmc,
	[PM1_STS_BIT] = smihandler_southbridge_pm1,
#if CONFIG(SOC_INTEL_COMMON_BLOCK_SMM_TCO_ENABLE)
	[TCO_STS_BIT] = smihandler_southbridge_tco,
#endif
};