1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * This file is created based on Intel Alder Lake Processor SA Datasheet
5 * Document number: 619503
9 #include <arch/ioapic.h>
10 #include <console/console.h>
11 #include <cpu/x86/msr.h>
12 #include <device/device.h>
13 #include <device/pci.h>
14 #include <intelblocks/cpulib.h>
15 #include <intelblocks/msr.h>
16 #include <intelblocks/power_limit.h>
17 #include <intelblocks/systemagent.h>
18 #include <soc/iomap.h>
19 #include <soc/soc_chip.h>
20 #include <soc/systemagent.h>
21 #include <spi_flash.h>
28 * Add all known fixed memory ranges for Host Controller/Memory
31 void soc_add_fixed_mmio_resources(struct device
*dev
, int *index
)
33 static const struct sa_mmio_descriptor soc_fixed_resources
[] = {
34 { MCHBAR
, MCH_BASE_ADDRESS
, MCH_BASE_SIZE
, "MCHBAR" },
35 { DMIBAR
, DMI_BASE_ADDRESS
, DMI_BASE_SIZE
, "DMIBAR" },
36 { EPBAR
, EP_BASE_ADDRESS
, EP_BASE_SIZE
, "EPBAR" },
37 { REGBAR
, REG_BASE_ADDRESS
, REG_BASE_SIZE
, "REGBAR" },
38 { EDRAMBAR
, EDRAM_BASE_ADDRESS
, EDRAM_BASE_SIZE
, "EDRAMBAR" },
40 /* first field (sa_mmio_descriptor.index) is not used, setting to 0: */
41 { 0, CRAB_ABORT_BASE_ADDR
, CRAB_ABORT_SIZE
, "CRAB_ABORT" },
42 { 0, TPM_BASE_ADDRESS
, TPM_SIZE
, "TPM" },
43 { 0, LT_SECURITY_BASE_ADDR
, LT_SECURITY_SIZE
, "LT_SECURITY" },
44 { 0, IO_APIC_ADDR
, APIC_SIZE
, "APIC" },
45 // PCH_PRESERVERD covers:
46 // TraceHub SW BAR, SBREG, PMC MBAR, SPI BAR0, SerialIo BAR in ACPI mode
47 // eSPI LGMR BAR, eSPI2 SEGMR BAR, TraceHub MTB BAR, TraceHub FW BAR
48 // see fsp/ClientOneSiliconPkg/Fru/AdlPch/Include/PchReservedResourcesAdpP.h
49 { 0, PCH_PRESERVED_BASE_ADDRESS
, PCH_PRESERVED_BASE_SIZE
, "PCH_RESERVED" },
52 sa_add_fixed_mmio_resources(dev
, index
, soc_fixed_resources
,
53 ARRAY_SIZE(soc_fixed_resources
));
55 /* Add Vt-d resources if VT-d is enabled */
56 if ((pci_read_config32(dev
, CAPID0_A
) & VTD_DISABLE
))
59 sa_add_fixed_mmio_resources(dev
, index
, soc_vtd_resources
,
60 ARRAY_SIZE(soc_vtd_resources
));
64 * set MMIO resource's fields
66 static void set_mmio_resource(
67 struct sa_mmio_descriptor
*resource
,
70 const char *description
)
72 if (resource
== NULL
) {
73 printk(BIOS_ERR
, "%s: argument resource is NULL for %s\n",
74 __func__
, description
);
77 resource
->base
= base
;
78 resource
->size
= size
;
79 resource
->description
= description
;
82 int soc_get_uncore_prmmr_base_and_mask(uint64_t *prmrr_base
,
86 msr
= rdmsr(MSR_PRMRR_BASE_0
);
87 *prmrr_base
= (uint64_t)msr
.hi
<< 32 | msr
.lo
;
88 msr
= rdmsr(MSR_PRMRR_PHYS_MASK
);
89 *prmrr_mask
= (uint64_t)msr
.hi
<< 32 | msr
.lo
;
96 * Add all known configurable memory ranges for Host Controller/Memory
99 void soc_add_configurable_mmio_resources(struct device
*dev
, int *resource_cnt
)
101 uint64_t size
, base
, tseg_base
;
103 struct sa_mmio_descriptor cfg_rsrc
[6]; /* Increase size when adding more resources */
106 size
= sa_get_mmcfg_size();
108 set_mmio_resource(&(cfg_rsrc
[count
++]), CONFIG_ECAM_MMCONF_BASE_ADDRESS
,
112 size
= sa_get_dsm_size();
114 base
= pci_read_config32(dev
, BDSM
) & 0xFFF00000;
115 set_mmio_resource(&(cfg_rsrc
[count
++]), base
, size
, "DSM");
119 size
= sa_get_tseg_size();
120 tseg_base
= sa_get_tseg_base();
122 set_mmio_resource(&(cfg_rsrc
[count
++]), tseg_base
, size
, "TSEG");
125 size
= get_valid_prmrr_size();
128 if (soc_get_uncore_prmmr_base_and_mask(&base
, &mask
) == 0) {
130 set_mmio_resource(&(cfg_rsrc
[count
++]), base
, size
, "PMRR");
132 printk(BIOS_ERR
, "SA: Failed to get PRMRR base and mask\n");
137 size
= sa_get_gsm_size();
139 base
= sa_get_gsm_base();
140 set_mmio_resource(&(cfg_rsrc
[count
++]), base
, size
, "GSM");
144 size
= sa_get_dpr_size();
146 /* DPR just below TSEG: */
147 base
= tseg_base
- size
;
148 set_mmio_resource(&(cfg_rsrc
[count
++]), base
, size
, "DPR");
151 /* Add all the above */
152 sa_add_fixed_mmio_resources(dev
, resource_cnt
, cfg_rsrc
, count
);
158 * Perform System Agent Initialization during Ramstage phase.
160 void soc_systemagent_init(struct device
*dev
)
162 struct soc_power_limits_config
*soc_config
;
169 /* Enable Power Aware Interrupt Routing */
170 enable_power_aware_intr();
172 config
= config_of_soc();
174 /* Get System Agent PCI ID */
175 sa
= pcidev_path_on_root(SA_DEVFN_ROOT
);
176 sa_pci_id
= sa
? pci_read_config16(sa
, PCI_DEVICE_ID
) : 0xFFFF;
180 /* Choose power limits configuration based on the CPU SA PCI ID and
182 for (i
= 0; i
< ARRAY_SIZE(cpuid_to_adl
); i
++) {
183 if (sa_pci_id
== cpuid_to_adl
[i
].cpu_id
&&
184 tdp
== cpuid_to_adl
[i
].cpu_tdp
) {
185 soc_config
= &config
->power_limits_config
[cpuid_to_adl
[i
].limits
];
186 set_power_limits(MOBILE_SKU_PL1_TIME_SEC
, soc_config
);
191 if (i
== ARRAY_SIZE(cpuid_to_adl
)) {
192 printk(BIOS_ERR
, "unknown SA ID: 0x%4x, skipped power limits configuration.\n",
198 uint32_t soc_systemagent_max_chan_capacity_mib(u8 capid0_a_ddrsz
)
200 switch (capid0_a_ddrsz
) {