blob: 8b644354ab1a105e89e942d7e3dbe3498e518bef [file] [log] [blame]
Angel Pons3bd1e3d2020-04-05 15:47:17 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahyb0005132015-05-12 18:19:47 -07002
Pratik Prajapati653f0192017-08-28 15:15:38 -07003#include <cpu/x86/msr.h>
Lee Leahyb0005132015-05-12 18:19:47 -07004#include <delay.h>
5#include <device/device.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +02006#include <device/pci_ops.h>
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +05307#include <intelblocks/power_limit.h>
Subrata Banik46a71782017-06-02 18:52:24 +05308#include <intelblocks/systemagent.h>
Lee Leahyb0005132015-05-12 18:19:47 -07009#include <soc/cpu.h>
10#include <soc/iomap.h>
Pratik Prajapati653f0192017-08-28 15:15:38 -070011#include <soc/msr.h>
Nico Huber2afe4dc2017-09-19 09:36:03 +020012#include <soc/pci_devs.h>
Lee Leahyb0005132015-05-12 18:19:47 -070013#include <soc/systemagent.h>
Nico Huber2afe4dc2017-09-19 09:36:03 +020014#include "chip.h"
15
16bool soc_is_vtd_capable(void)
17{
Kyösti Mälkki71756c212019-07-12 13:10:19 +030018 struct device *const root_dev = pcidev_path_on_root(SA_DEVFN_ROOT);
Nico Huber2afe4dc2017-09-19 09:36:03 +020019 return root_dev &&
20 !(pci_read_config32(root_dev, CAPID0_A) & VTD_DISABLE);
21}
Lee Leahyb0005132015-05-12 18:19:47 -070022
Subrata Banik46a71782017-06-02 18:52:24 +053023/*
24 * SoC implementation
25 *
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010026 * Add all known fixed memory ranges for Host Controller/Memory
Subrata Banik46a71782017-06-02 18:52:24 +053027 * controller.
28 */
29void soc_add_fixed_mmio_resources(struct device *dev, int *index)
Lee Leahyb0005132015-05-12 18:19:47 -070030{
Kyösti Mälkki71756c212019-07-12 13:10:19 +030031 struct device *const igd_dev = pcidev_path_on_root(SA_DEVFN_IGD);
32
Subrata Banik46a71782017-06-02 18:52:24 +053033 static const struct sa_mmio_descriptor soc_fixed_resources[] = {
Angel Pons98494882021-01-29 11:35:16 +010034 { PCIEXBAR, CONFIG_MMCONF_BASE_ADDRESS, CONFIG_MMCONF_LENGTH,
Subrata Banik46a71782017-06-02 18:52:24 +053035 "PCIEXBAR" },
36 { MCHBAR, MCH_BASE_ADDRESS, MCH_BASE_SIZE, "MCHBAR" },
37 { DMIBAR, DMI_BASE_ADDRESS, DMI_BASE_SIZE, "DMIBAR" },
38 { EPBAR, EP_BASE_ADDRESS, EP_BASE_SIZE, "EPBAR" },
39 { GDXCBAR, GDXC_BASE_ADDRESS, GDXC_BASE_SIZE, "GDXCBAR" },
40 { EDRAMBAR, EDRAM_BASE_ADDRESS, EDRAM_BASE_SIZE, "EDRAMBAR" },
41 };
Lee Leahyb0005132015-05-12 18:19:47 -070042
Subrata Banik46a71782017-06-02 18:52:24 +053043 sa_add_fixed_mmio_resources(dev, index, soc_fixed_resources,
44 ARRAY_SIZE(soc_fixed_resources));
Nico Huber2afe4dc2017-09-19 09:36:03 +020045
Angel Pons00f53a82021-04-05 12:03:08 +020046 if (soc_is_vtd_capable()) {
Maxim Polyakov58066652019-04-25 12:32:15 +030047 if (igd_dev && igd_dev->enabled)
48 sa_add_fixed_mmio_resources(dev, index,
49 &soc_gfxvt_mmio_descriptor, 1);
50
51 sa_add_fixed_mmio_resources(dev, index,
52 &soc_vtvc0_mmio_descriptor, 1);
53 }
Lee Leahyb0005132015-05-12 18:19:47 -070054}
55
Lee Leahy1d14b3e2015-05-12 18:23:27 -070056/*
Subrata Banik46a71782017-06-02 18:52:24 +053057 * SoC implementation
58 *
59 * Perform System Agent Initialization during Ramstage phase.
Lee Leahy1d14b3e2015-05-12 18:23:27 -070060 */
Subrata Banik46a71782017-06-02 18:52:24 +053061void soc_systemagent_init(struct device *dev)
Lee Leahyb0005132015-05-12 18:19:47 -070062{
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +053063 struct soc_power_limits_config *soc_config;
64 config_t *config;
65
Lee Leahyb0005132015-05-12 18:19:47 -070066 /* Enable Power Aware Interrupt Routing */
Subrata Banik46a71782017-06-02 18:52:24 +053067 enable_power_aware_intr();
Lee Leahyb0005132015-05-12 18:19:47 -070068
Subrata Banik46a71782017-06-02 18:52:24 +053069 /* Enable BIOS Reset CPL */
70 enable_bios_reset_cpl();
Lee Leahyb0005132015-05-12 18:19:47 -070071
72 /* Configure turbo power limits 1ms after reset complete bit */
73 mdelay(1);
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +053074 config = config_of_soc();
75 soc_config = &config->power_limits_config;
76 set_power_limits(MOBILE_SKU_PL1_TIME_SEC, soc_config);
Lee Leahyb0005132015-05-12 18:19:47 -070077}
Pratik Prajapati653f0192017-08-28 15:15:38 -070078
79int soc_get_uncore_prmmr_base_and_mask(uint64_t *prmrr_base,
80 uint64_t *prmrr_mask)
81{
82 msr_t msr;
Pratik Prajapati6a051f22017-08-28 15:30:20 -070083 msr = rdmsr(MSR_UNCORE_PRMRR_PHYS_BASE);
Pratik Prajapati653f0192017-08-28 15:15:38 -070084 *prmrr_base = (uint64_t) msr.hi << 32 | msr.lo;
Pratik Prajapati6a051f22017-08-28 15:30:20 -070085 msr = rdmsr(MSR_UNCORE_PRMRR_PHYS_MASK);
Pratik Prajapati653f0192017-08-28 15:15:38 -070086 *prmrr_mask = (uint64_t) msr.hi << 32 | msr.lo;
87 return 0;
88}
Patrick Rudolphbf72dcb2020-05-12 16:04:47 +020089
90uint32_t soc_systemagent_max_chan_capacity_mib(u8 capid0_a_ddrsz)
91{
92 switch (capid0_a_ddrsz) {
93 case 1:
94 return 8192;
95 case 2:
96 return 4096;
97 case 3:
98 return 2048;
99 default:
100 return 32768;
101 }
102}