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