Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_gnvs.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <arch/smp/mpspec.h> |
| 6 | #include <assert.h> |
| 7 | #include <cbmem.h> |
| 8 | #include <cpu/intel/turbo.h> |
| 9 | #include <device/mmio.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <intelblocks/acpi.h> |
| 12 | #include <soc/acpi.h> |
| 13 | #include <soc/cpu.h> |
| 14 | #include <soc/iomap.h> |
| 15 | #include <soc/msr.h> |
| 16 | #include <soc/pci_devs.h> |
| 17 | #include <soc/pm.h> |
| 18 | #include <soc/soc_util.h> |
| 19 | |
Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 20 | /* TODO: Check if the common/acpi weak function can be used */ |
| 21 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 22 | { |
| 23 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 24 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, 255); |
| 25 | return current; |
| 26 | } |
| 27 | |
| 28 | void acpi_create_gnvs(struct global_nvs *gnvs) |
| 29 | { |
| 30 | /* CPU core count */ |
| 31 | gnvs->pcnt = dev_count_cpu(); |
| 32 | printk(BIOS_DEBUG, "%s gnvs->pcnt: %d\n", __func__, gnvs->pcnt); |
| 33 | } |
| 34 | |
| 35 | int soc_madt_sci_irq_polarity(int sci) |
| 36 | { |
| 37 | if (sci >= 20) |
| 38 | return MP_IRQ_POLARITY_LOW; |
| 39 | else |
| 40 | return MP_IRQ_POLARITY_HIGH; |
| 41 | } |
| 42 | |
Marc Jones | 70ddbd8 | 2020-09-28 12:25:03 -0600 | [diff] [blame] | 43 | uint32_t soc_read_sci_irq_select(void) |
| 44 | { |
| 45 | struct device *dev = PCH_DEV_PMC; |
| 46 | |
| 47 | if (!dev) |
| 48 | return 0; |
| 49 | |
| 50 | return pci_read_config32(dev, PMC_ACPI_CNT); |
| 51 | } |
| 52 | |
Marc Jones | 2560ad3 | 2020-09-28 15:23:35 -0600 | [diff] [blame] | 53 | void soc_fill_fadt(acpi_fadt_t *fadt) |
| 54 | { |
| 55 | /* Clear flags set by common/block/acpi/acpi.c acpi_fill_fadt() */ |
Morgan Jang | 160cb33 | 2020-10-27 11:34:43 +0800 | [diff] [blame] | 56 | fadt->flags &= ~(ACPI_FADT_SEALED_CASE | ACPI_FADT_S4_RTC_WAKE); |
Marc Jones | 2560ad3 | 2020-09-28 15:23:35 -0600 | [diff] [blame] | 57 | } |
| 58 | |
Marc Jones | 521a03f | 2020-10-19 13:46:59 -0600 | [diff] [blame] | 59 | void uncore_inject_dsdt(const struct device *device) |
Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 60 | { |
| 61 | struct iiostack_resource stack_info = {0}; |
| 62 | |
Marc Jones | 2c70716 | 2020-10-31 15:29:14 -0600 | [diff] [blame^] | 63 | /* Only add RTxx entries once. */ |
| 64 | if (device->bus->secondary != 0) |
| 65 | return; |
| 66 | |
Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 67 | get_iiostack_info(&stack_info); |
| 68 | |
| 69 | acpigen_write_scope("\\_SB"); |
| 70 | |
| 71 | for (uint8_t stack = 0; stack < stack_info.no_of_stacks; ++stack) { |
| 72 | const STACK_RES *ri = &stack_info.res[stack]; |
| 73 | char rtname[16]; |
| 74 | |
| 75 | snprintf(rtname, sizeof(rtname), "RT%02x", stack); |
| 76 | |
| 77 | acpigen_write_name(rtname); |
| 78 | printk(BIOS_DEBUG, "\tCreating ResourceTemplate %s for stack: %d\n", |
| 79 | rtname, stack); |
| 80 | |
| 81 | acpigen_write_resourcetemplate_header(); |
| 82 | |
| 83 | /* bus resource */ |
| 84 | acpigen_resource_word(2, 0xc, 0, 0, ri->BusBase, ri->BusLimit, |
| 85 | 0x0, (ri->BusLimit - ri->BusBase + 1)); |
| 86 | |
| 87 | /* additional io resources on socket 0 bus 0 */ |
| 88 | if (stack == 0) { |
| 89 | /* ACPI 6.4.2.5 I/O Port Descriptor */ |
| 90 | acpigen_write_io16(0xCF8, 0xCFF, 0x1, 0x8, 1); |
| 91 | |
| 92 | /* IO decode CF8-CFF */ |
| 93 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x0000, 0x03AF, 0, 0x03B0); |
| 94 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03E0, 0x0CF7, 0, 0x0918); |
| 95 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03B0, 0x03BB, 0, 0x000C); |
| 96 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03C0, 0x03DF, 0, 0x0020); |
| 97 | } |
| 98 | |
| 99 | /* IO resource */ |
| 100 | acpigen_resource_word(1, 0xc, 0x3, 0, ri->PciResourceIoBase, |
| 101 | ri->PciResourceIoLimit, 0x0, |
| 102 | (ri->PciResourceIoLimit - ri->PciResourceIoBase + 1)); |
| 103 | |
| 104 | /* additional mem32 resources on socket 0 bus 0 */ |
| 105 | if (stack == 0) { |
| 106 | acpigen_resource_dword(0, 0xc, 3, 0, VGA_BASE_ADDRESS, |
| 107 | (VGA_BASE_ADDRESS + VGA_BASE_SIZE - 1), 0x0, |
| 108 | VGA_BASE_SIZE); |
| 109 | acpigen_resource_dword(0, 0xc, 1, 0, SPI_BASE_ADDRESS, |
| 110 | (SPI_BASE_ADDRESS + SPI_BASE_SIZE - 1), 0x0, |
| 111 | SPI_BASE_SIZE); |
| 112 | } |
| 113 | |
| 114 | /* Mem32 resource */ |
| 115 | acpigen_resource_dword(0, 0xc, 1, 0, ri->PciResourceMem32Base, |
| 116 | ri->PciResourceMem32Limit, 0x0, |
| 117 | (ri->PciResourceMem32Limit - ri->PciResourceMem32Base + 1)); |
| 118 | |
| 119 | /* Mem64 resource */ |
| 120 | acpigen_resource_qword(0, 0xc, 1, 0, ri->PciResourceMem64Base, |
| 121 | ri->PciResourceMem64Limit, 0x0, |
| 122 | (ri->PciResourceMem64Limit - ri->PciResourceMem64Base + 1)); |
| 123 | |
| 124 | acpigen_write_resourcetemplate_footer(); |
| 125 | } |
| 126 | acpigen_pop_len(); |
| 127 | } |
| 128 | |
Marc Jones | 7a25fb8 | 2020-10-19 16:32:05 -0600 | [diff] [blame] | 129 | /* TODO: See if we can use the common generate_p_state_entries */ |
| 130 | void soc_power_states_generation(int core, int cores_per_package) |
Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 131 | { |
| 132 | int ratio_min, ratio_max, ratio_turbo, ratio_step; |
| 133 | int coord_type, power_max, power_unit, num_entries; |
| 134 | int ratio, power, clock, clock_max; |
| 135 | msr_t msr; |
| 136 | |
| 137 | /* Determine P-state coordination type from MISC_PWR_MGMT[0] */ |
| 138 | msr = rdmsr(MSR_MISC_PWR_MGMT); |
| 139 | if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS) |
| 140 | coord_type = SW_ANY; |
| 141 | else |
| 142 | coord_type = HW_ALL; |
| 143 | |
| 144 | /* Get bus ratio limits and calculate clock speeds */ |
| 145 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 146 | ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */ |
| 147 | |
| 148 | /* Determine if this CPU has configurable TDP */ |
| 149 | if (cpu_config_tdp_levels()) { |
| 150 | /* Set max ratio to nominal TDP ratio */ |
| 151 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 152 | ratio_max = msr.lo & 0xff; |
| 153 | } else { |
| 154 | /* Max Non-Turbo Ratio */ |
| 155 | ratio_max = (msr.lo >> 8) & 0xff; |
| 156 | } |
| 157 | clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ; |
| 158 | |
| 159 | /* Calculate CPU TDP in mW */ |
| 160 | msr = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 161 | power_unit = 2 << ((msr.lo & 0xf) - 1); |
| 162 | msr = rdmsr(MSR_PKG_POWER_SKU); |
| 163 | power_max = ((msr.lo & 0x7fff) / power_unit) * 1000; |
| 164 | |
| 165 | /* Write _PCT indicating use of FFixedHW */ |
| 166 | acpigen_write_empty_PCT(); |
| 167 | |
| 168 | /* Write _PPC with no limit on supported P-state */ |
| 169 | acpigen_write_PPC_NVS(); |
| 170 | |
| 171 | /* Write PSD indicating configured coordination type */ |
| 172 | acpigen_write_PSD_package(core, 1, coord_type); |
| 173 | |
| 174 | /* Add P-state entries in _PSS table */ |
| 175 | acpigen_write_name("_PSS"); |
| 176 | |
| 177 | /* Determine ratio points */ |
| 178 | ratio_step = PSS_RATIO_STEP; |
| 179 | num_entries = ((ratio_max - ratio_min) / ratio_step) + 1; |
| 180 | if (num_entries > PSS_MAX_ENTRIES) { |
| 181 | ratio_step += 1; |
| 182 | num_entries = ((ratio_max - ratio_min) / ratio_step) + 1; |
| 183 | } |
| 184 | |
| 185 | /* P[T] is Turbo state if enabled */ |
| 186 | if (get_turbo_state() == TURBO_ENABLED) { |
| 187 | /* _PSS package count including Turbo */ |
| 188 | acpigen_write_package(num_entries + 2); |
| 189 | |
| 190 | msr = rdmsr(MSR_TURBO_RATIO_LIMIT); |
| 191 | ratio_turbo = msr.lo & 0xff; |
| 192 | |
| 193 | /* Add entry for Turbo ratio */ |
| 194 | acpigen_write_PSS_package( |
| 195 | clock_max + 1, /* MHz */ |
| 196 | power_max, /* mW */ |
| 197 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 198 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 199 | ratio_turbo << 8, /* control */ |
| 200 | ratio_turbo << 8); /* status */ |
| 201 | } else { |
| 202 | /* _PSS package count without Turbo */ |
| 203 | acpigen_write_package(num_entries + 1); |
| 204 | } |
| 205 | |
| 206 | /* First regular entry is max non-turbo ratio */ |
| 207 | acpigen_write_PSS_package( |
| 208 | clock_max, /* MHz */ |
| 209 | power_max, /* mW */ |
| 210 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 211 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 212 | ratio_max << 8, /* control */ |
| 213 | ratio_max << 8); /* status */ |
| 214 | |
| 215 | /* Generate the remaining entries */ |
| 216 | for (ratio = ratio_min + ((num_entries - 1) * ratio_step); |
| 217 | ratio >= ratio_min; ratio -= ratio_step) { |
| 218 | |
| 219 | /* Calculate power at this ratio */ |
| 220 | power = calculate_power(power_max, ratio_max, ratio); |
| 221 | clock = ratio * CONFIG_CPU_BCLK_MHZ; |
| 222 | //clock = 1; |
| 223 | acpigen_write_PSS_package( |
| 224 | clock, /* MHz */ |
| 225 | power, /* mW */ |
| 226 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 227 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 228 | ratio << 8, /* control */ |
| 229 | ratio << 8); /* status */ |
| 230 | } |
| 231 | |
| 232 | /* Fix package length */ |
| 233 | acpigen_pop_len(); |
| 234 | } |
| 235 | |
| 236 | unsigned long xeonsp_acpi_create_madt_lapics(unsigned long current) |
| 237 | { |
| 238 | struct device *cpu; |
| 239 | uint8_t num_cpus = 0; |
| 240 | |
| 241 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 242 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
| 243 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
| 244 | continue; |
| 245 | } |
| 246 | if (!cpu->enabled) |
| 247 | continue; |
| 248 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, |
| 249 | num_cpus, cpu->path.apic.apic_id); |
| 250 | num_cpus++; |
| 251 | } |
| 252 | |
| 253 | return current; |
| 254 | } |