blob: 9724f08d93a9ecf55b6155c6d06af612a760d56a [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 The Chromium OS Authors. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Stefan Reinauer8e073822012-04-04 00:07:22 +020015 */
16
17#include <arch/io.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020018#include <device/pci_ops.h>
Duncan Laurie04c5bae2012-08-13 09:37:42 -070019#include <console/post_codes.h>
Dennis Wassenberg0c047202015-09-10 12:03:45 +020020#include <cpu/x86/smm.h>
Arthur Heymansd2d2aef2018-01-16 14:19:37 +010021#include <southbridge/intel/common/rcba.h>
Zheng Bao600784e2013-02-07 17:30:23 +080022#include <spi-generic.h>
Nico Huber8e50b6d2018-02-04 15:52:18 +010023#include "chip.h"
24#include "pch.h"
Stefan Reinauer8e073822012-04-04 00:07:22 +020025
26void intel_pch_finalize_smm(void)
27{
Dennis Wassenberg0c047202015-09-10 12:03:45 +020028 u16 tco1_cnt;
29 u16 pmbase;
30
Nico Huber2ac149d2017-09-01 23:28:14 +020031 if (IS_ENABLED(CONFIG_LOCK_SPI_FLASH_RO) ||
32 IS_ENABLED(CONFIG_LOCK_SPI_FLASH_NO_ACCESS)) {
Vladimir Serbinenkod3b194e2015-05-12 12:39:53 +020033 /* Copy flash regions from FREG0-4 to PR0-4
34 and enable write protection bit31 */
35 int i;
36 u32 lockmask = (1 << 31);
Nico Huber2ac149d2017-09-01 23:28:14 +020037 if (IS_ENABLED(CONFIG_LOCK_SPI_FLASH_NO_ACCESS))
Vladimir Serbinenkod3b194e2015-05-12 12:39:53 +020038 lockmask |= (1 << 15);
39 for (i = 0; i < 20; i += 4)
40 RCBA32(0x3874 + i) = RCBA32(0x3854 + i) | lockmask;
41 }
Nico Huberd1fb5642013-07-01 16:02:36 +020042
Stefan Reinauer8e073822012-04-04 00:07:22 +020043 /* Lock SPIBAR */
44 RCBA32_OR(0x3804, (1 << 15));
Stefan Reinauer8e073822012-04-04 00:07:22 +020045
Martin Roth7a1a3ad2017-06-24 21:29:38 -060046#if IS_ENABLED(CONFIG_SPI_FLASH_SMM)
Duncan Laurie312ee0c2012-09-09 20:12:32 -070047 /* Re-init SPI driver to handle locked BAR */
48 spi_init();
49#endif
50
Stefan Reinauer8e073822012-04-04 00:07:22 +020051 /* TCLOCKDN: TC Lockdown */
52 RCBA32_OR(0x0050, (1 << 31));
53
54 /* BIOS Interface Lockdown */
55 RCBA32_OR(0x3410, (1 << 0));
56
57 /* Function Disable SUS Well Lockdown */
58 RCBA_AND_OR(8, 0x3420, ~0U, (1 << 7));
59
60 /* Global SMI Lock */
Patrick Rudolphc3686202017-05-03 17:50:00 +020061 pci_or_config16(PCH_LPC_DEV, GEN_PMCON_1, 1 << 4);
Stefan Reinauer8e073822012-04-04 00:07:22 +020062
63 /* GEN_PMCON Lock */
Patrick Rudolphc3686202017-05-03 17:50:00 +020064 pci_or_config8(PCH_LPC_DEV, GEN_PMCON_LOCK, (1 << 1) | (1 << 2));
Stefan Reinauer8e073822012-04-04 00:07:22 +020065
Patrick Rudolph7565cf12017-05-03 18:38:21 +020066 /* ETR3: CF9GR Lockdown */
67 pci_update_config32(PCH_LPC_DEV, ETR3, ~ETR3_CF9GR, ETR3_CF9LOCK);
68
Stefan Reinauer8e073822012-04-04 00:07:22 +020069 /* R/WO registers */
70 RCBA32(0x21a4) = RCBA32(0x21a4);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +030071 pci_write_config32(PCI_DEV(0, 27, 0), 0x74,
72 pci_read_config32(PCI_DEV(0, 27, 0), 0x74));
Duncan Laurie04c5bae2012-08-13 09:37:42 -070073
Dennis Wassenberg0c047202015-09-10 12:03:45 +020074 /* TCO_Lock */
75 pmbase = smm_get_pmbase();
76 tco1_cnt = inw(pmbase + TCO1_CNT);
77 tco1_cnt |= TCO_LOCK;
78 outw(tco1_cnt, pmbase + TCO1_CNT);
79
Duncan Laurie04c5bae2012-08-13 09:37:42 -070080 /* Indicate finalize step with post code */
81 outb(POST_OS_BOOT, 0x80);
Stefan Reinauer8e073822012-04-04 00:07:22 +020082}