blob: bec8676c1d365af6e7c18bbfa41bb52daf092737 [file] [log] [blame]
Lee Leahyb0005132015-05-12 18:19:47 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
Lee Leahy1d14b3e2015-05-12 18:23:27 -07005 * Copyright (C) 2015 Intel Corporation.
Lee Leahyb0005132015-05-12 18:19:47 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of 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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Lee Leahy1d14b3e2015-05-12 18:23:27 -070018 * Foundation, Inc.
Lee Leahyb0005132015-05-12 18:19:47 -070019 */
20
21#include <arch/io.h>
22#include <bootstate.h>
23#include <console/console.h>
24#include <console/post_codes.h>
25#include <cpu/x86/smm.h>
26#include <reg_script.h>
27#include <spi-generic.h>
28#include <stdlib.h>
29#include <soc/pci_devs.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070030#include <soc/pcr.h>
31#include <soc/pm.h>
32#include <soc/pmc.h>
Lee Leahyb0005132015-05-12 18:19:47 -070033#include <soc/spi.h>
34#include <soc/systemagent.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070035#include <device/pci.h>
Lee Leahyb0005132015-05-12 18:19:47 -070036
Lee Leahy1d14b3e2015-05-12 18:23:27 -070037static void pch_finalize_script(void)
38{
39 device_t dev;
40 uint32_t reg32, hsfs;
41 void *spibar = get_spi_bar();
42 u8 reg8;
43 u16 tcobase;
44 u16 tcocnt;
45 uint8_t *pmcbase;
46 u32 pmsyncreg;
Lee Leahyb0005132015-05-12 18:19:47 -070047
Lee Leahyb0005132015-05-12 18:19:47 -070048 /* Set SPI opcode menu */
Lee Leahy1d14b3e2015-05-12 18:23:27 -070049 write16(spibar + SPIBAR_PREOP, SPI_OPPREFIX);
50 write16(spibar + SPIBAR_OPTYPE, SPI_OPTYPE);
51 write32(spibar + SPIBAR_OPMENU_LOWER, SPI_OPMENU_LOWER);
52 write32(spibar + SPIBAR_OPMENU_UPPER, SPI_OPMENU_UPPER);
Lee Leahyb0005132015-05-12 18:19:47 -070053 /* Lock SPIBAR */
Lee Leahy1d14b3e2015-05-12 18:23:27 -070054 hsfs = read32(spibar + SPIBAR_HSFS);
55 hsfs |= SPIBAR_HSFS_FLOCKDN;
56 write32(spibar + SPIBAR_HSFS, hsfs);
Lee Leahyb0005132015-05-12 18:19:47 -070057
Lee Leahy1d14b3e2015-05-12 18:23:27 -070058 /*TCO Lock down*/
59 tcobase = pmc_tco_regs();
60 tcocnt = inw(tcobase + TCO1_CNT);
61 tcocnt |= TCO_LOCK;
62 outw(tcocnt, tcobase + TCO1_CNT);
Lee Leahyb0005132015-05-12 18:19:47 -070063
64 /* Global SMI Lock */
Lee Leahy1d14b3e2015-05-12 18:23:27 -070065 dev = PCH_DEV_PMC;
66 reg8 = pci_read_config8(dev, GEN_PMCON_A);
67 reg8 |= SMI_LOCK;
68 pci_write_config8(dev, GEN_PMCON_A, reg8);
Lee Leahyb0005132015-05-12 18:19:47 -070069
Lee Leahy1d14b3e2015-05-12 18:23:27 -070070 /* Lock down ABASE and sleep stretching policy */
71 reg32 = pci_read_config32(dev, GEN_PMCON_B);
72 reg32 |= (SLP_STR_POL_LOCK | ACPI_BASE_LOCK);
73 pci_write_config32(dev, GEN_PMCON_B, reg32);
Lee Leahyb0005132015-05-12 18:19:47 -070074
75 /* PMSYNC */
Lee Leahy1d14b3e2015-05-12 18:23:27 -070076 pmcbase = pmc_mmio_regs();
77 pmsyncreg = read32(pmcbase + PMSYNC_TPR_CFG);
78 pmsyncreg |= PMSYNC_LOCK;
79 write32(pmcbase + PMSYNC_TPR_CFG, pmsyncreg);
80}
Lee Leahyb0005132015-05-12 18:19:47 -070081
Lee Leahy1d14b3e2015-05-12 18:23:27 -070082static void soc_finalize(void *unused)
Lee Leahyb0005132015-05-12 18:19:47 -070083{
84 printk(BIOS_DEBUG, "Finalizing chipset.\n");
Lee Leahy1d14b3e2015-05-12 18:23:27 -070085 pch_finalize_script();
Lee Leahyb0005132015-05-12 18:19:47 -070086
87 /* Indicate finalize step with post code */
88 post_code(POST_OS_BOOT);
89}
90
Lee Leahy1d14b3e2015-05-12 18:23:27 -070091BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, soc_finalize, NULL);
92BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, soc_finalize, NULL);