blob: d203bdadff10c0805b60f540a8d64954d199f402 [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>
Sean Rhodes66c80622021-07-13 07:23:22 +01009#include <option.h>
Lee Leahyb0005132015-05-12 18:19:47 -070010#include <soc/cpu.h>
11#include <soc/iomap.h>
Pratik Prajapati653f0192017-08-28 15:15:38 -070012#include <soc/msr.h>
Nico Huber2afe4dc2017-09-19 09:36:03 +020013#include <soc/pci_devs.h>
Lee Leahyb0005132015-05-12 18:19:47 -070014#include <soc/systemagent.h>
Sean Rhodes66c80622021-07-13 07:23:22 +010015#include <types.h>
Nico Huber2afe4dc2017-09-19 09:36:03 +020016#include "chip.h"
17
Sean Rhodes66c80622021-07-13 07:23:22 +010018bool soc_vtd_enabled(void)
Nico Huber2afe4dc2017-09-19 09:36:03 +020019{
Sean Rhodes66c80622021-07-13 07:23:22 +010020 const unsigned int vtd = get_uint_option("vtd", 1);
21 if (!vtd)
22 return false;
Kyösti Mälkki71756c212019-07-12 13:10:19 +030023 struct device *const root_dev = pcidev_path_on_root(SA_DEVFN_ROOT);
Nico Huber2afe4dc2017-09-19 09:36:03 +020024 return root_dev &&
25 !(pci_read_config32(root_dev, CAPID0_A) & VTD_DISABLE);
26}
Lee Leahyb0005132015-05-12 18:19:47 -070027
Subrata Banik46a71782017-06-02 18:52:24 +053028/*
29 * SoC implementation
30 *
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010031 * Add all known fixed memory ranges for Host Controller/Memory
Subrata Banik46a71782017-06-02 18:52:24 +053032 * controller.
33 */
34void soc_add_fixed_mmio_resources(struct device *dev, int *index)
Lee Leahyb0005132015-05-12 18:19:47 -070035{
Subrata Banik46a71782017-06-02 18:52:24 +053036 static const struct sa_mmio_descriptor soc_fixed_resources[] = {
Shelley Chen4e9bb332021-10-20 15:43:45 -070037 { PCIEXBAR, CONFIG_ECAM_MMCONF_BASE_ADDRESS, CONFIG_ECAM_MMCONF_LENGTH,
Subrata Banik46a71782017-06-02 18:52:24 +053038 "PCIEXBAR" },
39 { MCHBAR, MCH_BASE_ADDRESS, MCH_BASE_SIZE, "MCHBAR" },
40 { DMIBAR, DMI_BASE_ADDRESS, DMI_BASE_SIZE, "DMIBAR" },
41 { EPBAR, EP_BASE_ADDRESS, EP_BASE_SIZE, "EPBAR" },
42 { GDXCBAR, GDXC_BASE_ADDRESS, GDXC_BASE_SIZE, "GDXCBAR" },
43 { EDRAMBAR, EDRAM_BASE_ADDRESS, EDRAM_BASE_SIZE, "EDRAMBAR" },
44 };
Lee Leahyb0005132015-05-12 18:19:47 -070045
Subrata Banik46a71782017-06-02 18:52:24 +053046 sa_add_fixed_mmio_resources(dev, index, soc_fixed_resources,
47 ARRAY_SIZE(soc_fixed_resources));
Nico Huber2afe4dc2017-09-19 09:36:03 +020048
Sean Rhodes66c80622021-07-13 07:23:22 +010049 if (soc_vtd_enabled()) {
Angel Pons7ff3f312021-06-23 12:13:57 +020050 if (is_devfn_enabled(SA_DEVFN_IGD))
Maxim Polyakov58066652019-04-25 12:32:15 +030051 sa_add_fixed_mmio_resources(dev, index,
52 &soc_gfxvt_mmio_descriptor, 1);
53
54 sa_add_fixed_mmio_resources(dev, index,
55 &soc_vtvc0_mmio_descriptor, 1);
56 }
Lee Leahyb0005132015-05-12 18:19:47 -070057}
58
Lee Leahy1d14b3e2015-05-12 18:23:27 -070059/*
Subrata Banik46a71782017-06-02 18:52:24 +053060 * SoC implementation
61 *
62 * Perform System Agent Initialization during Ramstage phase.
Lee Leahy1d14b3e2015-05-12 18:23:27 -070063 */
Subrata Banik46a71782017-06-02 18:52:24 +053064void soc_systemagent_init(struct device *dev)
Lee Leahyb0005132015-05-12 18:19:47 -070065{
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +053066 struct soc_power_limits_config *soc_config;
67 config_t *config;
68
Lee Leahyb0005132015-05-12 18:19:47 -070069 /* Enable Power Aware Interrupt Routing */
Subrata Banik46a71782017-06-02 18:52:24 +053070 enable_power_aware_intr();
Lee Leahyb0005132015-05-12 18:19:47 -070071
Subrata Banik46a71782017-06-02 18:52:24 +053072 /* Enable BIOS Reset CPL */
73 enable_bios_reset_cpl();
Lee Leahyb0005132015-05-12 18:19:47 -070074
75 /* Configure turbo power limits 1ms after reset complete bit */
76 mdelay(1);
Sumeet R Pawnikar97c54642020-05-10 01:24:11 +053077 config = config_of_soc();
78 soc_config = &config->power_limits_config;
79 set_power_limits(MOBILE_SKU_PL1_TIME_SEC, soc_config);
Lee Leahyb0005132015-05-12 18:19:47 -070080}
Pratik Prajapati653f0192017-08-28 15:15:38 -070081
82int soc_get_uncore_prmmr_base_and_mask(uint64_t *prmrr_base,
83 uint64_t *prmrr_mask)
84{
85 msr_t msr;
Pratik Prajapati6a051f22017-08-28 15:30:20 -070086 msr = rdmsr(MSR_UNCORE_PRMRR_PHYS_BASE);
Elyes Haouas9018dee2022-11-18 15:07:33 +010087 *prmrr_base = (uint64_t)msr.hi << 32 | msr.lo;
Pratik Prajapati6a051f22017-08-28 15:30:20 -070088 msr = rdmsr(MSR_UNCORE_PRMRR_PHYS_MASK);
Elyes Haouas9018dee2022-11-18 15:07:33 +010089 *prmrr_mask = (uint64_t)msr.hi << 32 | msr.lo;
Pratik Prajapati653f0192017-08-28 15:15:38 -070090 return 0;
91}
Patrick Rudolphbf72dcb2020-05-12 16:04:47 +020092
93uint32_t soc_systemagent_max_chan_capacity_mib(u8 capid0_a_ddrsz)
94{
95 switch (capid0_a_ddrsz) {
96 case 1:
97 return 8192;
98 case 2:
99 return 4096;
100 case 3:
101 return 2048;
102 default:
103 return 32768;
104 }
105}