Angel Pons | 3bd1e3d | 2020-04-05 15:47:17 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 2 | |
Pratik Prajapati | 653f019 | 2017-08-28 15:15:38 -0700 | [diff] [blame] | 3 | #include <cpu/x86/msr.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 4 | #include <delay.h> |
| 5 | #include <device/device.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Sumeet R Pawnikar | 97c5464 | 2020-05-10 01:24:11 +0530 | [diff] [blame] | 7 | #include <intelblocks/power_limit.h> |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 8 | #include <intelblocks/systemagent.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 9 | #include <soc/cpu.h> |
| 10 | #include <soc/iomap.h> |
Pratik Prajapati | 653f019 | 2017-08-28 15:15:38 -0700 | [diff] [blame] | 11 | #include <soc/msr.h> |
Nico Huber | 2afe4dc | 2017-09-19 09:36:03 +0200 | [diff] [blame] | 12 | #include <soc/pci_devs.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 13 | #include <soc/systemagent.h> |
Nico Huber | 2afe4dc | 2017-09-19 09:36:03 +0200 | [diff] [blame] | 14 | #include "chip.h" |
| 15 | |
| 16 | bool soc_is_vtd_capable(void) |
| 17 | { |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 18 | struct device *const root_dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
Nico Huber | 2afe4dc | 2017-09-19 09:36:03 +0200 | [diff] [blame] | 19 | return root_dev && |
| 20 | !(pci_read_config32(root_dev, CAPID0_A) & VTD_DISABLE); |
| 21 | } |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 22 | |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 23 | /* |
| 24 | * SoC implementation |
| 25 | * |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 26 | * Add all known fixed memory ranges for Host Controller/Memory |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 27 | * controller. |
| 28 | */ |
| 29 | void soc_add_fixed_mmio_resources(struct device *dev, int *index) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 30 | { |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 31 | struct device *const igd_dev = pcidev_path_on_root(SA_DEVFN_IGD); |
| 32 | |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 33 | static const struct sa_mmio_descriptor soc_fixed_resources[] = { |
Angel Pons | 9849488 | 2021-01-29 11:35:16 +0100 | [diff] [blame] | 34 | { PCIEXBAR, CONFIG_MMCONF_BASE_ADDRESS, CONFIG_MMCONF_LENGTH, |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 35 | "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 Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 42 | |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 43 | sa_add_fixed_mmio_resources(dev, index, soc_fixed_resources, |
| 44 | ARRAY_SIZE(soc_fixed_resources)); |
Nico Huber | 2afe4dc | 2017-09-19 09:36:03 +0200 | [diff] [blame] | 45 | |
Angel Pons | 00f53a8 | 2021-04-05 12:03:08 +0200 | [diff] [blame] | 46 | if (soc_is_vtd_capable()) { |
Maxim Polyakov | 5806665 | 2019-04-25 12:32:15 +0300 | [diff] [blame] | 47 | 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 Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 56 | /* |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 57 | * SoC implementation |
| 58 | * |
| 59 | * Perform System Agent Initialization during Ramstage phase. |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 60 | */ |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 61 | void soc_systemagent_init(struct device *dev) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 62 | { |
Sumeet R Pawnikar | 97c5464 | 2020-05-10 01:24:11 +0530 | [diff] [blame] | 63 | struct soc_power_limits_config *soc_config; |
| 64 | config_t *config; |
| 65 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 66 | /* Enable Power Aware Interrupt Routing */ |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 67 | enable_power_aware_intr(); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 68 | |
Subrata Banik | 46a7178 | 2017-06-02 18:52:24 +0530 | [diff] [blame] | 69 | /* Enable BIOS Reset CPL */ |
| 70 | enable_bios_reset_cpl(); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 71 | |
| 72 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 73 | mdelay(1); |
Sumeet R Pawnikar | 97c5464 | 2020-05-10 01:24:11 +0530 | [diff] [blame] | 74 | config = config_of_soc(); |
| 75 | soc_config = &config->power_limits_config; |
| 76 | set_power_limits(MOBILE_SKU_PL1_TIME_SEC, soc_config); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 77 | } |
Pratik Prajapati | 653f019 | 2017-08-28 15:15:38 -0700 | [diff] [blame] | 78 | |
| 79 | int soc_get_uncore_prmmr_base_and_mask(uint64_t *prmrr_base, |
| 80 | uint64_t *prmrr_mask) |
| 81 | { |
| 82 | msr_t msr; |
Pratik Prajapati | 6a051f2 | 2017-08-28 15:30:20 -0700 | [diff] [blame] | 83 | msr = rdmsr(MSR_UNCORE_PRMRR_PHYS_BASE); |
Pratik Prajapati | 653f019 | 2017-08-28 15:15:38 -0700 | [diff] [blame] | 84 | *prmrr_base = (uint64_t) msr.hi << 32 | msr.lo; |
Pratik Prajapati | 6a051f2 | 2017-08-28 15:30:20 -0700 | [diff] [blame] | 85 | msr = rdmsr(MSR_UNCORE_PRMRR_PHYS_MASK); |
Pratik Prajapati | 653f019 | 2017-08-28 15:15:38 -0700 | [diff] [blame] | 86 | *prmrr_mask = (uint64_t) msr.hi << 32 | msr.lo; |
| 87 | return 0; |
| 88 | } |
Patrick Rudolph | bf72dcb | 2020-05-12 16:04:47 +0200 | [diff] [blame] | 89 | |
| 90 | uint32_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 | } |