blob: 9c453e46115b56501231b956788cabe175036015 [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>
Duncan Laurie04c5bae2012-08-13 09:37:42 -070018#include <console/post_codes.h>
Dennis Wassenberg0c047202015-09-10 12:03:45 +020019#include <cpu/x86/smm.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020020#include "pch.h"
Zheng Bao600784e2013-02-07 17:30:23 +080021#include <spi-generic.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020022
23void intel_pch_finalize_smm(void)
24{
Dennis Wassenberg0c047202015-09-10 12:03:45 +020025 u16 tco1_cnt;
26 u16 pmbase;
27
Vladimir Serbinenkod3b194e2015-05-12 12:39:53 +020028 if (CONFIG_LOCK_SPI_ON_RESUME_RO || CONFIG_LOCK_SPI_ON_RESUME_NO_ACCESS) {
29 /* Copy flash regions from FREG0-4 to PR0-4
30 and enable write protection bit31 */
31 int i;
32 u32 lockmask = (1 << 31);
33 if (CONFIG_LOCK_SPI_ON_RESUME_NO_ACCESS)
34 lockmask |= (1 << 15);
35 for (i = 0; i < 20; i += 4)
36 RCBA32(0x3874 + i) = RCBA32(0x3854 + i) | lockmask;
37 }
Nico Huberd1fb5642013-07-01 16:02:36 +020038
Stefan Reinauer8e073822012-04-04 00:07:22 +020039 /* Set SPI opcode menu */
40 RCBA16(0x3894) = SPI_OPPREFIX;
41 RCBA16(0x3896) = SPI_OPTYPE;
42 RCBA32(0x3898) = SPI_OPMENU_LOWER;
43 RCBA32(0x389c) = SPI_OPMENU_UPPER;
44
45 /* Lock SPIBAR */
46 RCBA32_OR(0x3804, (1 << 15));
Stefan Reinauer8e073822012-04-04 00:07:22 +020047
Duncan Laurie312ee0c2012-09-09 20:12:32 -070048#if CONFIG_SPI_FLASH_SMM
49 /* Re-init SPI driver to handle locked BAR */
50 spi_init();
51#endif
52
Stefan Reinauer8e073822012-04-04 00:07:22 +020053 /* TCLOCKDN: TC Lockdown */
54 RCBA32_OR(0x0050, (1 << 31));
55
56 /* BIOS Interface Lockdown */
57 RCBA32_OR(0x3410, (1 << 0));
58
59 /* Function Disable SUS Well Lockdown */
60 RCBA_AND_OR(8, 0x3420, ~0U, (1 << 7));
61
62 /* Global SMI Lock */
Patrick Rudolphc3686202017-05-03 17:50:00 +020063 pci_or_config16(PCH_LPC_DEV, GEN_PMCON_1, 1 << 4);
Stefan Reinauer8e073822012-04-04 00:07:22 +020064
65 /* GEN_PMCON Lock */
Patrick Rudolphc3686202017-05-03 17:50:00 +020066 pci_or_config8(PCH_LPC_DEV, GEN_PMCON_LOCK, (1 << 1) | (1 << 2));
Stefan Reinauer8e073822012-04-04 00:07:22 +020067
Patrick Rudolph7565cf12017-05-03 18:38:21 +020068 /* ETR3: CF9GR Lockdown */
69 pci_update_config32(PCH_LPC_DEV, ETR3, ~ETR3_CF9GR, ETR3_CF9LOCK);
70
Stefan Reinauer8e073822012-04-04 00:07:22 +020071 /* R/WO registers */
72 RCBA32(0x21a4) = RCBA32(0x21a4);
Kyösti Mälkkifd98c652013-07-26 08:50:53 +030073 pci_write_config32(PCI_DEV(0, 27, 0), 0x74,
74 pci_read_config32(PCI_DEV(0, 27, 0), 0x74));
Duncan Laurie04c5bae2012-08-13 09:37:42 -070075
Dennis Wassenberg0c047202015-09-10 12:03:45 +020076 /* TCO_Lock */
77 pmbase = smm_get_pmbase();
78 tco1_cnt = inw(pmbase + TCO1_CNT);
79 tco1_cnt |= TCO_LOCK;
80 outw(tco1_cnt, pmbase + TCO1_CNT);
81
Duncan Laurie04c5bae2012-08-13 09:37:42 -070082 /* Indicate finalize step with post code */
83 outb(POST_OS_BOOT, 0x80);
Stefan Reinauer8e073822012-04-04 00:07:22 +020084}