blob: 5d7e1e00341a216860724a068c7ff187e994bb36 [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.
Pratik Prajapati1b25c8e2018-05-18 18:07:25 -07005 * Copyright (C) 2015-2018 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.
Lee Leahyb0005132015-05-12 18:19:47 -070015 */
16
17#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070020#include <bootstate.h>
21#include <console/console.h>
22#include <console/post_codes.h>
Pratik Prajapati1b25c8e2018-05-18 18:07:25 -070023#include <cpu/x86/mp.h>
Lee Leahyb0005132015-05-12 18:19:47 -070024#include <cpu/x86/smm.h>
Subrata Banike7ceae72017-03-08 17:59:40 +053025#include <device/pci.h>
Pratik Prajapati1b25c8e2018-05-18 18:07:25 -070026#include <intelblocks/cpulib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070027#include <intelblocks/lpc_lib.h>
Subrata Banikc51df932018-05-08 11:58:01 +053028#include <intelblocks/p2sb.h>
Subrata Banike7ceae72017-03-08 17:59:40 +053029#include <intelblocks/pcr.h>
Lee Leahyb0005132015-05-12 18:19:47 -070030#include <reg_script.h>
31#include <spi-generic.h>
Dhaval Sharma9dca83c2016-01-18 17:28:20 +053032#include <soc/me.h>
Rizwan Qureshicf73c132016-08-04 20:01:12 +053033#include <soc/p2sb.h>
Lee Leahyb0005132015-05-12 18:19:47 -070034#include <soc/pci_devs.h>
Subrata Banike7ceae72017-03-08 17:59:40 +053035#include <soc/pcr_ids.h>
Lee Leahy1d14b3e2015-05-12 18:23:27 -070036#include <soc/pm.h>
Barnali Sarkar0dddcd72016-08-02 17:49:56 +053037#include <soc/smbus.h>
Lee Leahyb0005132015-05-12 18:19:47 -070038#include <soc/systemagent.h>
Subrata Banik771d6112017-11-29 16:17:13 +053039#include <soc/thermal.h>
Barnali Sarkar71464452017-03-31 18:11:49 +053040#include <stdlib.h>
Pratik Prajapati1b25c8e2018-05-18 18:07:25 -070041#include <timer.h>
Subrata Banike7ceae72017-03-08 17:59:40 +053042
Elyes HAOUASc3385072019-03-21 15:38:06 +010043#include "chip.h"
44
Subrata Banike7ceae72017-03-08 17:59:40 +053045#define PSF_BASE_ADDRESS 0xA00
46#define PCR_PSFX_T0_SHDW_PCIEN 0x1C
47#define PCR_PSFX_T0_SHDW_PCIEN_FUNDIS (1 << 8)
Archana Patni7846e342015-11-11 01:29:23 +053048
Subrata Banik7837c202018-05-07 17:13:40 +053049static void disable_sideband_access(void)
Archana Patni7846e342015-11-11 01:29:23 +053050{
Subrata Banik7837c202018-05-07 17:13:40 +053051 p2sb_disable_sideband_access();
Barnali Sarkarfbf10182017-08-11 18:38:38 +053052
53 /* hide p2sb device */
Subrata Banikc51df932018-05-08 11:58:01 +053054 p2sb_hide();
Barnali Sarkarfbf10182017-08-11 18:38:38 +053055}
56
57static void pch_disable_heci(void)
58{
Archana Patni7846e342015-11-11 01:29:23 +053059 /* unhide p2sb device */
Subrata Banikc51df932018-05-08 11:58:01 +053060 p2sb_unhide();
Archana Patni7846e342015-11-11 01:29:23 +053061
62 /* disable heci */
Subrata Banike7ceae72017-03-08 17:59:40 +053063 pcr_or32(PID_PSF1, PSF_BASE_ADDRESS + PCR_PSFX_T0_SHDW_PCIEN,
64 PCR_PSFX_T0_SHDW_PCIEN_FUNDIS);
Archana Patni7846e342015-11-11 01:29:23 +053065
Subrata Banik7837c202018-05-07 17:13:40 +053066 disable_sideband_access();
Archana Patni7846e342015-11-11 01:29:23 +053067}
Lee Leahyb0005132015-05-12 18:19:47 -070068
Subrata Banikc51df932018-05-08 11:58:01 +053069static void pch_finalize_script(struct device *dev)
Lee Leahy1d14b3e2015-05-12 18:23:27 -070070{
Barnali Sarkar71464452017-03-31 18:11:49 +053071 uint32_t reg32;
Lee Leahy1d14b3e2015-05-12 18:23:27 -070072 uint8_t *pmcbase;
Archana Patni7846e342015-11-11 01:29:23 +053073 config_t *config;
Archana Patni6c1bf272015-12-18 23:38:21 +053074 u8 reg8;
Lee Leahyb0005132015-05-12 18:19:47 -070075
Dhaval Sharma9dca83c2016-01-18 17:28:20 +053076 /* Display me status before we hide it */
77 intel_me_status();
78
Subrata Banik639bf8a2017-08-25 12:08:59 +053079 pmcbase = pmc_mmio_regs();
Archana Patni7846e342015-11-11 01:29:23 +053080 config = dev->chip_info;
Archana Patni6c1bf272015-12-18 23:38:21 +053081
82 /*
Subrata Banik771d6112017-11-29 16:17:13 +053083 * Set low maximum temp value used for dynamic thermal sensor
84 * shutdown consideration.
85 *
86 * If Dynamic Thermal Shutdown is enabled then PMC logic shuts down the
87 * thermal sensor when CPU is in a C-state and DTS Temp <= LTT.
88 */
89 pch_thermal_configuration();
90
91 /*
Archana Patni6c1bf272015-12-18 23:38:21 +053092 * Disable ACPI PM timer based on dt policy
93 *
94 * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
95 * Disabling ACPI PM timer also switches off TCO
96 */
97
98 if (config->PmTimerDisabled) {
99 reg8 = read8(pmcbase + PCH_PWRM_ACPI_TMR_CTL);
100 reg8 |= (1 << 1);
101 write8(pmcbase + PCH_PWRM_ACPI_TMR_CTL, reg8);
102 }
103
Naresh G Solankic261c4b2017-04-25 12:09:07 +0530104 /* Disable XTAL shutdown qualification for low power idle. */
105 if (config->s0ix_enable) {
106 reg32 = read32(pmcbase + CIR31C);
107 reg32 |= XTALSDQDIS;
108 write32(pmcbase + CIR31C, reg32);
109 }
110
Archana Patni6c1bf272015-12-18 23:38:21 +0530111 /* we should disable Heci1 based on the devicetree policy */
Archana Patni7846e342015-11-11 01:29:23 +0530112 if (config->HeciEnabled == 0)
113 pch_disable_heci();
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700114}
Lee Leahyb0005132015-05-12 18:19:47 -0700115
Subrata Banikc51df932018-05-08 11:58:01 +0530116static void soc_lockdown(struct device *dev)
Rizwan Qureshie64f7942015-11-19 16:01:54 +0530117{
Barnali Sarkar0818a2a2017-08-17 11:52:39 +0530118 struct soc_intel_skylake_config *config;
Rizwan Qureshie64f7942015-11-19 16:01:54 +0530119 u8 reg8;
Barnali Sarkar0818a2a2017-08-17 11:52:39 +0530120
Barnali Sarkar0818a2a2017-08-17 11:52:39 +0530121 config = dev->chip_info;
Rizwan Qureshie64f7942015-11-19 16:01:54 +0530122
123 /* Global SMI Lock */
124 if (config->LockDownConfigGlobalSmi == 0) {
Rizwan Qureshie64f7942015-11-19 16:01:54 +0530125 reg8 = pci_read_config8(dev, GEN_PMCON_A);
126 reg8 |= SMI_LOCK;
127 pci_write_config8(dev, GEN_PMCON_A, reg8);
128 }
Rizwan Qureshie64f7942015-11-19 16:01:54 +0530129}
130
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700131static void soc_finalize(void *unused)
Lee Leahyb0005132015-05-12 18:19:47 -0700132{
Subrata Banikc51df932018-05-08 11:58:01 +0530133 struct device *dev;
134
135 dev = PCH_DEV_PMC;
136
137 /* Check if PMC is enabled, else return */
138 if (dev == NULL || dev->chip_info == NULL)
139 return;
140
Lee Leahyb0005132015-05-12 18:19:47 -0700141 printk(BIOS_DEBUG, "Finalizing chipset.\n");
Rizwan Qureshie64f7942015-11-19 16:01:54 +0530142
Subrata Banikc51df932018-05-08 11:58:01 +0530143 pch_finalize_script(dev);
Lee Leahyb0005132015-05-12 18:19:47 -0700144
Pratik Prajapati1b25c8e2018-05-18 18:07:25 -0700145 printk(BIOS_DEBUG, "Clearing MCA.\n");
146 mp_run_on_all_cpus(mca_configure, NULL, 17 * USECS_PER_SEC);
147
Subrata Banikc51df932018-05-08 11:58:01 +0530148 soc_lockdown(dev);
Rizwan Qureshie64f7942015-11-19 16:01:54 +0530149
Duncan Laurie6f0e6fa2016-02-09 09:40:39 -0800150 printk(BIOS_DEBUG, "Finalizing SMM.\n");
151 outb(APM_CNT_FINALIZE, APM_CNT);
152
Lee Leahyb0005132015-05-12 18:19:47 -0700153 /* Indicate finalize step with post code */
154 post_code(POST_OS_BOOT);
155}
156
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700157BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, soc_finalize, NULL);
158BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, soc_finalize, NULL);