| 1 |
|
| 2 |
|
| 3 |
#include <arch/ioapic.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <cpu/cpu.h> |
| 6 |
#include <cpu/x86/msr.h> |
| 7 |
#include <delay.h> |
| 8 |
#include <device/device.h> |
| 9 |
#include <device/pci.h> |
| 10 |
#include <intelblocks/acpi.h> |
| 11 |
#include <intelblocks/cpulib.h> |
| 12 |
#include <intelblocks/msr.h> |
| 13 |
#include <intelblocks/power_limit.h> |
| 14 |
#include <intelblocks/systemagent.h> |
| 15 |
#include <soc/iomap.h> |
| 16 |
#include <soc/soc_chip.h> |
| 17 |
#include <soc/systemagent.h> |
| 18 |
#include <static.h> |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
void soc_add_fixed_mmio_resources(struct device *dev, int *index) |
| 27 |
{ |
| 28 |
static const struct sa_mmio_descriptor soc_fixed_resources[] = { |
| 29 |
{ MCHBAR, MCH_BASE_ADDRESS, MCH_BASE_SIZE, "MCHBAR" }, |
| 30 |
{ SAFBAR, SAF_BASE_ADDRESS, SAF_BASE_SIZE, "SAFBAR" }, |
| 31 |
{ EPBAR, EP_BASE_ADDRESS, EP_BASE_SIZE, "EPBAR" }, |
| 32 |
{ REGBAR, REG_BASE_ADDRESS, REG_BASE_SIZE, "REGBAR" }, |
| 33 |
|
| 34 |
{ 0, CRAB_ABORT_BASE_ADDR, CRAB_ABORT_SIZE, "CRAB_ABORT" }, |
| 35 |
{ 0, LT_SECURITY_BASE_ADDR, LT_SECURITY_SIZE, "LT_SECURITY" }, |
| 36 |
{ 0, IO_APIC_ADDR, APIC_SIZE, "APIC" }, |
| 37 |
{ 0, PCH_PRESERVED_BASE_ADDRESS, PCH_PRESERVED_BASE_SIZE, "PCH_RESERVED" }, |
| 38 |
}; |
| 39 |
|
| 40 |
sa_add_fixed_mmio_resources(dev, index, soc_fixed_resources, |
| 41 |
ARRAY_SIZE(soc_fixed_resources)); |
| 42 |
|
| 43 |
|
| 44 |
if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE)) |
| 45 |
return; |
| 46 |
|
| 47 |
sa_add_fixed_mmio_resources(dev, index, soc_vtd_resources, |
| 48 |
ARRAY_SIZE(soc_vtd_resources)); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
static void set_mmio_resource( |
| 55 |
struct sa_mmio_descriptor *resource, |
| 56 |
uint64_t base, |
| 57 |
uint64_t size, |
| 58 |
const char *description) |
| 59 |
{ |
| 60 |
if (resource == NULL) { |
| 61 |
printk(BIOS_ERR, "%s: argument resource is NULL for %s\n", |
| 62 |
__func__, description); |
| 63 |
return; |
| 64 |
} |
| 65 |
resource->base = base; |
| 66 |
resource->size = size; |
| 67 |
resource->description = description; |
| 68 |
} |
| 69 |
|
| 70 |
int soc_get_uncore_prmmr_base_and_mask(uint64_t *prmrr_base, |
| 71 |
uint64_t *prmrr_mask) |
| 72 |
{ |
| 73 |
msr_t msr; |
| 74 |
msr = rdmsr(MSR_PRMRR_BASE_0); |
| 75 |
*prmrr_base = (uint64_t)msr.hi << 32 | msr.lo; |
| 76 |
msr = rdmsr(MSR_PRMRR_PHYS_MASK); |
| 77 |
*prmrr_mask = (uint64_t)msr.hi << 32 | msr.lo; |
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
void soc_add_configurable_mmio_resources(struct device *dev, int *resource_cnt) |
| 88 |
{ |
| 89 |
uint64_t size, base, tseg_base; |
| 90 |
int count = 0; |
| 91 |
struct sa_mmio_descriptor cfg_rsrc[6]; |
| 92 |
|
| 93 |
|
| 94 |
size = sa_get_mmcfg_size(); |
| 95 |
if (size > 0) |
| 96 |
set_mmio_resource(&(cfg_rsrc[count++]), CONFIG_ECAM_MMCONF_BASE_ADDRESS, |
| 97 |
size, "MMCONF"); |
| 98 |
|
| 99 |
|
| 100 |
size = sa_get_dsm_size(); |
| 101 |
if (size > 0) { |
| 102 |
base = pci_read_config32(dev, BDSM) & 0xFFF00000; |
| 103 |
set_mmio_resource(&(cfg_rsrc[count++]), base, size, "DSM"); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
size = sa_get_tseg_size(); |
| 108 |
tseg_base = sa_get_tseg_base(); |
| 109 |
if (size > 0) |
| 110 |
set_mmio_resource(&(cfg_rsrc[count++]), tseg_base, size, "TSEG"); |
| 111 |
|
| 112 |
|
| 113 |
size = get_valid_prmrr_size(); |
| 114 |
if (size > 0) { |
| 115 |
uint64_t mask; |
| 116 |
if (soc_get_uncore_prmmr_base_and_mask(&base, &mask) == 0) { |
| 117 |
base &= mask; |
| 118 |
set_mmio_resource(&(cfg_rsrc[count++]), base, size, "PMRR"); |
| 119 |
} else { |
| 120 |
printk(BIOS_ERR, "SA: Failed to get PRMRR base and mask\n"); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
size = sa_get_gsm_size(); |
| 126 |
if (size > 0) { |
| 127 |
base = sa_get_gsm_base(); |
| 128 |
set_mmio_resource(&(cfg_rsrc[count++]), base, size, "GSM"); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
size = sa_get_dpr_size(); |
| 133 |
if (size > 0) { |
| 134 |
|
| 135 |
base = tseg_base - size; |
| 136 |
set_mmio_resource(&(cfg_rsrc[count++]), base, size, "DPR"); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
sa_add_fixed_mmio_resources(dev, resource_cnt, cfg_rsrc, count); |
| 141 |
} |
| 142 |
|
| 143 |
static void configure_tdp(struct device *dev) |
| 144 |
{ |
| 145 |
struct soc_power_limits_config *soc_config; |
| 146 |
struct device *sa; |
| 147 |
uint16_t sa_pci_id; |
| 148 |
u8 tdp; |
| 149 |
size_t i; |
| 150 |
bool config_tdp = false; |
| 151 |
struct soc_intel_pantherlake_config *config; |
| 152 |
|
| 153 |
config = config_of_soc(); |
| 154 |
|
| 155 |
|
| 156 |
sa = pcidev_path_on_root(PCI_DEVFN_ROOT); |
| 157 |
sa_pci_id = sa ? pci_read_config16(sa, PCI_DEVICE_ID) : 0xFFFF; |
| 158 |
|
| 159 |
if (sa_pci_id == 0xFFFF) { |
| 160 |
printk(BIOS_WARNING, "Unknown SA PCI Device!\n"); |
| 161 |
return; |
| 162 |
} |
| 163 |
|
| 164 |
tdp = get_cpu_tdp(); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
for (i = 0; i < ARRAY_SIZE(cpuid_to_ptl); i++) { |
| 171 |
if (sa_pci_id == cpuid_to_ptl[i].cpu_id && |
| 172 |
tdp == cpuid_to_ptl[i].cpu_tdp) { |
| 173 |
soc_config = &config->power_limits_config[cpuid_to_ptl[i].limits]; |
| 174 |
if (config->enable_fast_vmode[VR_DOMAIN_IA] && |
| 175 |
soc_config->tdp_pl4_fastvmode) |
| 176 |
soc_config->tdp_pl4 = soc_config->tdp_pl4_fastvmode; |
| 177 |
set_power_limits(MOBILE_SKU_PL1_TIME_SEC, soc_config); |
| 178 |
config_tdp = true; |
| 179 |
printk(BIOS_DEBUG, "Configured power limits for SA PCI ID: 0x%4x\n", |
| 180 |
sa_pci_id); |
| 181 |
break; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
if (!config_tdp) { |
| 186 |
printk(BIOS_WARNING, "Skipped power limits configuration for SA PCI ID: 0x%4x\n", |
| 187 |
sa_pci_id); |
| 188 |
return; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
union pcode_mailbox_command { |
| 193 |
struct { |
| 194 |
uint32_t command: 8; |
| 195 |
uint32_t param1: 8; |
| 196 |
uint32_t param2: 13; |
| 197 |
uint32_t reserved: 2; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
uint32_t runbusy: 1; |
| 204 |
} fields; |
| 205 |
uint32_t data; |
| 206 |
}; |
| 207 |
|
| 208 |
union pcode_scaling_factor { |
| 209 |
struct { |
| 210 |
|
| 211 |
uint32_t scaling_factor: 16; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
uint32_t num_equivalent_module: 8; |
| 217 |
uint32_t reserved: 8; |
| 218 |
} fields; |
| 219 |
uint32_t data; |
| 220 |
}; |
| 221 |
|
| 222 |
#define MAILBOX_WAIT_TIMEOUT_US 1000 |
| 223 |
#define PCODE_READ_CORE_SCALING_FACTOR_CMD 0x21 |
| 224 |
|
| 225 |
static bool poll_mailbox_ready(void) |
| 226 |
{ |
| 227 |
union pcode_mailbox_command cmd; |
| 228 |
size_t i; |
| 229 |
|
| 230 |
for (i = 0; i < MAILBOX_WAIT_TIMEOUT_US; i++) { |
| 231 |
cmd.data = MCHBAR32(PCODE_MAILBOX_INTERFACE); |
| 232 |
if (!cmd.fields.runbusy) |
| 233 |
return true; |
| 234 |
udelay(1); |
| 235 |
} |
| 236 |
return false; |
| 237 |
} |
| 238 |
|
| 239 |
static u16 u88_to_scaling_factor(u16 u88) |
| 240 |
{ |
| 241 |
unsigned int tmp = (u88 & 0xff) * 100; |
| 242 |
unsigned int fraction = tmp / (1 << 8); |
| 243 |
|
| 244 |
|
| 245 |
if (((tmp & 0xff) << 1) >= (1 << 8)) |
| 246 |
fraction++; |
| 247 |
return ((u88 >> 8) * 100) + fraction; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
enum cb_err soc_read_core_scaling_factors(u16 *performance, u16 *efficient) |
| 266 |
{ |
| 267 |
extern struct cpu_info cpu_infos[]; |
| 268 |
union pcode_mailbox_command cmd = { |
| 269 |
.fields = { |
| 270 |
.command = PCODE_READ_CORE_SCALING_FACTOR_CMD, |
| 271 |
.runbusy = 1 |
| 272 |
} |
| 273 |
}; |
| 274 |
union pcode_scaling_factor res; |
| 275 |
bool has_efficient_core = false; |
| 276 |
|
| 277 |
if (!performance || !efficient) |
| 278 |
return CB_ERR_ARG; |
| 279 |
|
| 280 |
for (size_t i = 0; i < CONFIG_MAX_CPUS; i++) { |
| 281 |
struct device *cpu = cpu_infos[i].cpu; |
| 282 |
|
| 283 |
if (!cpu) |
| 284 |
continue; |
| 285 |
|
| 286 |
if (cpu->path.apic.core_type != CPU_TYPE_PERF) |
| 287 |
has_efficient_core = true; |
| 288 |
|
| 289 |
if (cpu->path.apic.core_type == CPU_TYPE_PERF && *performance) |
| 290 |
continue; |
| 291 |
|
| 292 |
cmd.fields.param1 = cpu->path.apic.module_id; |
| 293 |
|
| 294 |
if (!poll_mailbox_ready()) { |
| 295 |
printk(BIOS_ERR, "pcode mailbox is busy\n"); |
| 296 |
return CB_ERR; |
| 297 |
} |
| 298 |
|
| 299 |
MCHBAR32(PCODE_MAILBOX_INTERFACE) = cmd.data; |
| 300 |
|
| 301 |
if (!poll_mailbox_ready()) { |
| 302 |
printk(BIOS_ERR, "pcode command mailbox not completing in time\n"); |
| 303 |
return CB_ERR; |
| 304 |
} |
| 305 |
|
| 306 |
res.data = MCHBAR32(PCODE_MAILBOX_DATA); |
| 307 |
|
| 308 |
if (cpu->path.apic.core_type == CPU_TYPE_PERF) |
| 309 |
*performance = u88_to_scaling_factor(res.fields.scaling_factor); |
| 310 |
else |
| 311 |
*efficient = u88_to_scaling_factor(res.fields.scaling_factor); |
| 312 |
|
| 313 |
if (*performance && *efficient) |
| 314 |
break; |
| 315 |
} |
| 316 |
|
| 317 |
if (!*performance) { |
| 318 |
printk(BIOS_ERR, "Could not read performance scaling factor\n"); |
| 319 |
return CB_ERR; |
| 320 |
} |
| 321 |
if (has_efficient_core && !*efficient) { |
| 322 |
printk(BIOS_ERR, "Could not read efficient scaling factor\n"); |
| 323 |
return CB_ERR; |
| 324 |
} |
| 325 |
return CB_SUCCESS; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
void soc_systemagent_init(struct device *dev) |
| 334 |
{ |
| 335 |
|
| 336 |
enable_power_aware_intr(); |
| 337 |
|
| 338 |
|
| 339 |
configure_tdp(dev); |
| 340 |
} |
| 341 |
|
| 342 |
uint32_t soc_systemagent_max_chan_capacity_mib(u8 capid0_a_ddrsz) |
| 343 |
{ |
| 344 |
switch (capid0_a_ddrsz) { |
| 345 |
case 1: |
| 346 |
return 8192; |
| 347 |
case 2: |
| 348 |
return 4096; |
| 349 |
case 3: |
| 350 |
return 2048; |
| 351 |
default: |
| 352 |
return 65536; |
| 353 |
} |
| 354 |
} |