Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * ACPI - create the Fixed ACPI Description Tables (FADT) |
| 5 | */ |
| 6 | |
| 7 | #include <string.h> |
| 8 | #include <console/console.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 9 | #include <acpi/acpi.h> |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 10 | #include <acpi/acpi_gnvs.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 11 | #include <acpi/acpigen.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 12 | #include <device/pci_ops.h> |
| 13 | #include <arch/ioapic.h> |
Raul E Rangel | 93b62e6 | 2020-01-31 12:53:45 -0700 | [diff] [blame] | 14 | #include <arch/smp/mpspec.h> |
Jason Glenesk | 498015d | 2020-12-10 03:28:38 -0800 | [diff] [blame] | 15 | #include <cpu/amd/cpuid.h> |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 16 | #include <cpu/amd/msr.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 17 | #include <cpu/x86/smm.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <amdblocks/acpimmio.h> |
| 21 | #include <amdblocks/acpi.h> |
Raul E Rangel | 1c88b10 | 2021-02-11 10:35:32 -0700 | [diff] [blame^] | 22 | #include <amdblocks/chip.h> |
Felix Held | dd2f3fa | 2021-02-08 22:23:54 +0100 | [diff] [blame] | 23 | #include <amdblocks/cpu.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 24 | #include <soc/acpi.h> |
| 25 | #include <soc/pci_devs.h> |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 26 | #include <soc/msr.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 27 | #include <soc/southbridge.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 28 | #include <soc/nvs.h> |
| 29 | #include <soc/gpio.h> |
| 30 | #include <version.h> |
Raul E Rangel | 93b62e6 | 2020-01-31 12:53:45 -0700 | [diff] [blame] | 31 | #include "chip.h" |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 32 | |
| 33 | unsigned long acpi_fill_madt(unsigned long current) |
| 34 | { |
Raul E Rangel | 93b62e6 | 2020-01-31 12:53:45 -0700 | [diff] [blame] | 35 | const struct soc_amd_picasso_config *cfg = config_of_soc(); |
| 36 | unsigned int i; |
| 37 | uint8_t irq; |
| 38 | uint8_t flags; |
| 39 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 40 | /* create all subtables for processors */ |
| 41 | current = acpi_create_madt_lapics(current); |
| 42 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 43 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 44 | CONFIG_PICASSO_FCH_IOAPIC_ID, IO_APIC_ADDR, 0); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 45 | |
Jason Glenesk | f459a40 | 2020-09-02 16:49:10 -0700 | [diff] [blame] | 46 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current, |
| 47 | CONFIG_PICASSO_GNB_IOAPIC_ID, GNB_IO_APIC_ADDR, IO_APIC_INTERRUPTS); |
| 48 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 49 | /* 0: mean bus 0--->ISA */ |
| 50 | /* 0: PIC 0 */ |
| 51 | /* 2: APIC 2 */ |
| 52 | /* 5 mean: 0101 --> Edge-triggered, Active high */ |
| 53 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 54 | current, 0, 0, 2, 0); |
Raul E Rangel | 93b62e6 | 2020-01-31 12:53:45 -0700 | [diff] [blame] | 55 | current += acpi_create_madt_irqoverride( |
| 56 | (acpi_madt_irqoverride_t *)current, 0, 9, 9, |
| 57 | MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW); |
| 58 | |
| 59 | for (i = 0; i < ARRAY_SIZE(cfg->irq_override); ++i) { |
| 60 | irq = cfg->irq_override[i].irq; |
| 61 | flags = cfg->irq_override[i].flags; |
| 62 | |
| 63 | if (!flags) |
| 64 | continue; |
| 65 | |
| 66 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, 0, |
| 67 | irq, irq, flags); |
| 68 | } |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 69 | |
| 70 | /* create all subtables for processors */ |
| 71 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, |
| 72 | 0xff, 5, 1); |
| 73 | /* 1: LINT1 connect to NMI */ |
| 74 | |
| 75 | return current; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Reference section 5.2.9 Fixed ACPI Description Table (FADT) |
| 80 | * in the ACPI 3.0b specification. |
| 81 | */ |
Kyösti Mälkki | 61ef71b | 2020-05-30 18:54:39 +0300 | [diff] [blame] | 82 | void acpi_fill_fadt(acpi_fadt_t *fadt) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 83 | { |
Raul E Rangel | 1c88b10 | 2021-02-11 10:35:32 -0700 | [diff] [blame^] | 84 | const struct soc_amd_common_config *cfg = soc_get_common_config(); |
Martin Roth | eca8faa | 2019-12-01 16:49:19 -0700 | [diff] [blame] | 85 | |
Felix Held | 757d645 | 2021-02-04 21:31:49 +0100 | [diff] [blame] | 86 | printk(BIOS_DEBUG, "pm_base: 0x%04x\n", ACPI_IO_BASE); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 87 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 88 | fadt->sci_int = 9; /* IRQ 09 - ACPI SCI */ |
| 89 | |
Kyösti Mälkki | 0a9e72e | 2019-08-11 01:22:28 +0300 | [diff] [blame] | 90 | if (permanent_smi_handler()) { |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 91 | fadt->smi_cmd = APM_CNT; |
| 92 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 93 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 97 | fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 98 | fadt->pm_tmr_blk = ACPI_PM_TMR_BLK; |
| 99 | fadt->gpe0_blk = ACPI_GPE0_BLK; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 100 | |
| 101 | fadt->pm1_evt_len = 4; /* 32 bits */ |
| 102 | fadt->pm1_cnt_len = 2; /* 16 bits */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 103 | fadt->pm_tmr_len = 4; /* 32 bits */ |
| 104 | fadt->gpe0_blk_len = 8; /* 64 bits */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 105 | |
| 106 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 107 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 108 | fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */ |
| 109 | fadt->duty_width = 3; /* CLK_VAL bits 3:1 */ |
Raul E Rangel | 041fcf5 | 2020-08-12 12:13:35 -0600 | [diff] [blame] | 110 | fadt->day_alrm = 0x0d; |
| 111 | fadt->mon_alrm = 0; |
| 112 | fadt->century = 0x32; |
Martin Roth | eca8faa | 2019-12-01 16:49:19 -0700 | [diff] [blame] | 113 | fadt->iapc_boot_arch = cfg->fadt_boot_arch; /* legacy free default */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 114 | fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */ |
Martin Roth | eca8faa | 2019-12-01 16:49:19 -0700 | [diff] [blame] | 115 | fadt->flags |= ACPI_FADT_WBINVD | /* See table 5-34 ACPI 6.3 spec */ |
| 116 | ACPI_FADT_C1_SUPPORTED | |
| 117 | ACPI_FADT_S4_RTC_WAKE | |
| 118 | ACPI_FADT_32BIT_TIMER | |
| 119 | ACPI_FADT_PCI_EXPRESS_WAKE | |
| 120 | ACPI_FADT_PLATFORM_CLOCK | |
| 121 | ACPI_FADT_S4_RTC_VALID | |
| 122 | ACPI_FADT_REMOTE_POWER_ON; |
| 123 | fadt->flags |= cfg->fadt_flags; /* additional board-specific flags */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 124 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 125 | fadt->ARM_boot_arch = 0; /* MUST be 0 ACPI 3.0 */ |
| 126 | fadt->FADT_MinorVersion = 0; /* MUST be 0 ACPI 3.0 */ |
| 127 | |
| 128 | fadt->x_firmware_ctl_l = 0; /* set to 0 if firmware_ctrl is used */ |
| 129 | fadt->x_firmware_ctl_h = 0; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 130 | |
| 131 | fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 132 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 133 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
| 134 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 135 | fadt->x_pm1a_evt_blk.addrl = ACPI_PM_EVT_BLK; |
| 136 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 137 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 138 | fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 139 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 140 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 141 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 142 | fadt->x_pm1a_cnt_blk.addrl = ACPI_PM1_CNT_BLK; |
| 143 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 144 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 145 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 146 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 147 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 148 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 149 | fadt->x_pm_tmr_blk.addrl = ACPI_PM_TMR_BLK; |
| 150 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 151 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 152 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 153 | fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */ |
| 154 | fadt->x_gpe0_blk.bit_offset = 0; |
Angel Pons | a23aff3 | 2020-06-21 20:47:54 +0200 | [diff] [blame] | 155 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 156 | fadt->x_gpe0_blk.addrl = ACPI_GPE0_BLK; |
| 157 | fadt->x_gpe0_blk.addrh = 0x0; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 158 | } |
| 159 | |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 160 | static uint32_t get_pstate_core_freq(msr_t pstate_def) |
| 161 | { |
| 162 | uint32_t core_freq, core_freq_mul, core_freq_div; |
| 163 | bool valid_freq_divisor; |
| 164 | |
| 165 | /* Core frequency multiplier */ |
| 166 | core_freq_mul = pstate_def.lo & PSTATE_DEF_LO_FREQ_MUL_MASK; |
| 167 | |
| 168 | /* Core frequency divisor ID */ |
| 169 | core_freq_div = |
| 170 | (pstate_def.lo & PSTATE_DEF_LO_FREQ_DIV_MASK) >> PSTATE_DEF_LO_FREQ_DIV_SHIFT; |
| 171 | |
| 172 | if (core_freq_div == 0) { |
| 173 | return 0; |
| 174 | } else if ((core_freq_div >= PSTATE_DEF_LO_FREQ_DIV_MIN) |
| 175 | && (core_freq_div <= PSTATE_DEF_LO_EIGHTH_STEP_MAX)) { |
| 176 | /* Allow 1/8 integer steps for this range */ |
| 177 | valid_freq_divisor = 1; |
| 178 | } else if ((core_freq_div > PSTATE_DEF_LO_EIGHTH_STEP_MAX) |
| 179 | && (core_freq_div <= PSTATE_DEF_LO_FREQ_DIV_MAX) && !(core_freq_div & 0x1)) { |
| 180 | /* Only allow 1/4 integer steps for this range */ |
| 181 | valid_freq_divisor = 1; |
| 182 | } else { |
| 183 | valid_freq_divisor = 0; |
| 184 | } |
| 185 | |
| 186 | if (valid_freq_divisor) { |
| 187 | /* 25 * core_freq_mul / (core_freq_div / 8) */ |
| 188 | core_freq = |
| 189 | ((PSTATE_DEF_LO_CORE_FREQ_BASE * core_freq_mul * 8) / (core_freq_div)); |
| 190 | } else { |
| 191 | printk(BIOS_WARNING, "Undefined core_freq_div %x used. Force to 1.\n", |
| 192 | core_freq_div); |
| 193 | core_freq = (PSTATE_DEF_LO_CORE_FREQ_BASE * core_freq_mul); |
| 194 | } |
| 195 | return core_freq; |
| 196 | } |
| 197 | |
| 198 | static uint32_t get_pstate_core_power(msr_t pstate_def) |
| 199 | { |
| 200 | uint32_t voltage_in_uvolts, core_vid, current_value_amps, current_divisor, power_in_mw; |
| 201 | |
| 202 | /* Core voltage ID */ |
| 203 | core_vid = |
| 204 | (pstate_def.lo & PSTATE_DEF_LO_CORE_VID_MASK) >> PSTATE_DEF_LO_CORE_VID_SHIFT; |
| 205 | |
| 206 | /* Current value in amps */ |
| 207 | current_value_amps = |
| 208 | (pstate_def.lo & PSTATE_DEF_LO_CUR_VAL_MASK) >> PSTATE_DEF_LO_CUR_VAL_SHIFT; |
| 209 | |
| 210 | /* Current divisor */ |
| 211 | current_divisor = |
| 212 | (pstate_def.lo & PSTATE_DEF_LO_CUR_DIV_MASK) >> PSTATE_DEF_LO_CUR_DIV_SHIFT; |
| 213 | |
| 214 | /* Voltage */ |
| 215 | if ((core_vid >= 0xF8) && (core_vid <= 0xFF)) { |
| 216 | /* Voltage off for VID codes 0xF8 to 0xFF */ |
| 217 | voltage_in_uvolts = 0; |
| 218 | } else { |
| 219 | voltage_in_uvolts = |
| 220 | SERIAL_VID_MAX_MICROVOLTS - (SERIAL_VID_DECODE_MICROVOLTS * core_vid); |
| 221 | } |
| 222 | |
| 223 | /* Power in mW */ |
| 224 | power_in_mw = (voltage_in_uvolts) / 1000 * current_value_amps; |
| 225 | |
| 226 | switch (current_divisor) { |
| 227 | case 0: |
| 228 | break; |
| 229 | case 1: |
| 230 | power_in_mw = power_in_mw / 10L; |
| 231 | break; |
| 232 | case 2: |
| 233 | power_in_mw = power_in_mw / 100L; |
| 234 | break; |
| 235 | case 3: |
| 236 | /* current_divisor is set to an undefined value.*/ |
| 237 | printk(BIOS_WARNING, "Undefined current_divisor set for enabled P-state .\n"); |
| 238 | power_in_mw = 0; |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | return power_in_mw; |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * Populate structure describing enabled p-states and return count of enabled p-states. |
| 247 | */ |
| 248 | static size_t get_pstate_info(struct acpi_sw_pstate *pstate_values, |
| 249 | struct acpi_xpss_sw_pstate *pstate_xpss_values) |
| 250 | { |
| 251 | msr_t pstate_def; |
| 252 | size_t pstate_count, pstate; |
| 253 | uint32_t pstate_enable, max_pstate; |
| 254 | |
| 255 | pstate_count = 0; |
| 256 | max_pstate = (rdmsr(PS_LIM_REG).lo & PS_LIM_MAX_VAL_MASK) >> PS_MAX_VAL_SHFT; |
| 257 | |
| 258 | for (pstate = 0; pstate <= max_pstate; pstate++) { |
| 259 | pstate_def = rdmsr(PSTATE_0_MSR + pstate); |
| 260 | |
| 261 | pstate_enable = (pstate_def.hi & PSTATE_DEF_HI_ENABLE_MASK) |
| 262 | >> PSTATE_DEF_HI_ENABLE_SHIFT; |
| 263 | if (!pstate_enable) |
| 264 | continue; |
| 265 | |
| 266 | pstate_values[pstate_count].core_freq = get_pstate_core_freq(pstate_def); |
| 267 | pstate_values[pstate_count].power = get_pstate_core_power(pstate_def); |
| 268 | pstate_values[pstate_count].transition_latency = 0; |
| 269 | pstate_values[pstate_count].bus_master_latency = 0; |
| 270 | pstate_values[pstate_count].control_value = pstate; |
| 271 | pstate_values[pstate_count].status_value = pstate; |
| 272 | |
| 273 | pstate_xpss_values[pstate_count].core_freq = |
| 274 | (uint64_t)pstate_values[pstate_count].core_freq; |
| 275 | pstate_xpss_values[pstate_count].power = |
| 276 | (uint64_t)pstate_values[pstate_count].power; |
| 277 | pstate_xpss_values[pstate_count].transition_latency = 0; |
| 278 | pstate_xpss_values[pstate_count].bus_master_latency = 0; |
| 279 | pstate_xpss_values[pstate_count].control_value = (uint64_t)pstate; |
| 280 | pstate_xpss_values[pstate_count].status_value = (uint64_t)pstate; |
| 281 | pstate_count++; |
| 282 | } |
| 283 | |
| 284 | return pstate_count; |
| 285 | } |
| 286 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 287 | void generate_cpu_entries(const struct device *device) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 288 | { |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 289 | int logical_cores; |
| 290 | size_t pstate_count, cpu, proc_blk_len; |
| 291 | struct acpi_sw_pstate pstate_values[MAX_PSTATES] = { {0} }; |
| 292 | struct acpi_xpss_sw_pstate pstate_xpss_values[MAX_PSTATES] = { {0} }; |
| 293 | uint32_t threads_per_core, proc_blk_addr; |
| 294 | uint32_t cstate_base_address = |
| 295 | rdmsr(MSR_CSTATE_ADDRESS).lo & MSR_CSTATE_ADDRESS_MASK; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 296 | |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 297 | const acpi_addr_t perf_ctrl = { |
| 298 | .space_id = ACPI_ADDRESS_SPACE_FIXED, |
| 299 | .bit_width = 64, |
| 300 | .addrl = PS_CTL_REG, |
| 301 | }; |
| 302 | const acpi_addr_t perf_sts = { |
| 303 | .space_id = ACPI_ADDRESS_SPACE_FIXED, |
| 304 | .bit_width = 64, |
| 305 | .addrl = PS_STS_REG, |
| 306 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 307 | |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 308 | acpi_cstate_t cstate_info[] = { |
| 309 | [0] = { |
| 310 | .ctype = 1, |
| 311 | .latency = 1, |
| 312 | .power = 0, |
| 313 | .resource = { |
| 314 | .space_id = ACPI_ADDRESS_SPACE_FIXED, |
| 315 | .bit_width = 2, |
| 316 | .bit_offset = 2, |
| 317 | .addrl = 0, |
| 318 | .addrh = 0, |
| 319 | }, |
| 320 | }, |
| 321 | [1] = { |
| 322 | .ctype = 2, |
| 323 | .latency = 400, |
| 324 | .power = 0, |
| 325 | .resource = { |
| 326 | .space_id = ACPI_ADDRESS_SPACE_IO, |
| 327 | .bit_width = 8, |
| 328 | .bit_offset = 0, |
| 329 | .addrl = cstate_base_address + 1, |
| 330 | .addrh = 0, |
| 331 | .access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS, |
| 332 | }, |
| 333 | }, |
| 334 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 335 | |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 336 | threads_per_core = ((cpuid_ebx(CPUID_EBX_CORE_ID) & CPUID_EBX_THREADS_MASK) |
| 337 | >> CPUID_EBX_THREADS_SHIFT) |
| 338 | + 1; |
| 339 | pstate_count = get_pstate_info(pstate_values, pstate_xpss_values); |
| 340 | logical_cores = get_cpu_count(); |
| 341 | |
| 342 | for (cpu = 0; cpu < logical_cores; cpu++) { |
| 343 | |
| 344 | if (cpu == 0) { |
| 345 | /* BSP values for \_SB.Pxxx */ |
| 346 | proc_blk_len = 6; |
| 347 | proc_blk_addr = ACPI_GPE0_BLK; |
| 348 | } else { |
| 349 | /* AP values for \_SB.Pxxx */ |
| 350 | proc_blk_addr = 0; |
| 351 | proc_blk_len = 0; |
| 352 | } |
| 353 | |
| 354 | acpigen_write_processor(cpu, proc_blk_addr, proc_blk_len); |
| 355 | |
| 356 | acpigen_write_pct_package(&perf_ctrl, &perf_sts); |
| 357 | |
| 358 | acpigen_write_pss_object(pstate_values, pstate_count); |
| 359 | |
| 360 | acpigen_write_xpss_object(pstate_xpss_values, pstate_count); |
| 361 | |
| 362 | if (CONFIG(ACPI_SSDT_PSD_INDEPENDENT)) |
| 363 | acpigen_write_PSD_package(cpu / threads_per_core, threads_per_core, |
| 364 | HW_ALL); |
| 365 | else |
| 366 | acpigen_write_PSD_package(0, logical_cores, SW_ALL); |
| 367 | |
| 368 | acpigen_write_PPC(0); |
| 369 | |
| 370 | acpigen_write_CST_package(cstate_info, ARRAY_SIZE(cstate_info)); |
| 371 | |
| 372 | acpigen_write_CSD_package(cpu >> 1, threads_per_core, HW_ALL, 0); |
| 373 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 374 | acpigen_pop_len(); |
| 375 | } |
Kyösti Mälkki | da321d8 | 2021-01-27 20:22:33 +0200 | [diff] [blame] | 376 | |
| 377 | acpigen_write_scope("\\"); |
| 378 | acpigen_write_name_integer("PCNT", logical_cores); |
| 379 | acpigen_pop_len(); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 380 | } |
| 381 | |
Kyösti Mälkki | e1ff3cd | 2020-06-29 03:17:05 +0300 | [diff] [blame] | 382 | void soc_fill_gnvs(struct global_nvs *gnvs) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 383 | { |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 384 | /* Set unknown wake source */ |
| 385 | gnvs->pm1i = ~0ULL; |
| 386 | gnvs->gpei = ~0ULL; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 387 | } |
| 388 | |
Eric Lai | 7cee566 | 2020-12-28 14:52:11 +0800 | [diff] [blame] | 389 | static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num) |
| 390 | { |
| 391 | if (gpio_num >= SOC_GPIO_TOTAL_PINS) { |
| 392 | printk(BIOS_WARNING, "Warning: Pin %d should be smaller than" |
| 393 | " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS); |
| 394 | return -1; |
| 395 | } |
| 396 | /* op (gpio_num) */ |
| 397 | acpigen_emit_namestring(op); |
| 398 | acpigen_write_integer(gpio_num); |
| 399 | return 0; |
| 400 | } |
| 401 | |
Eric Lai | d7a3643 | 2020-12-28 15:32:54 +0800 | [diff] [blame] | 402 | static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num) |
| 403 | { |
| 404 | if (gpio_num >= SOC_GPIO_TOTAL_PINS) { |
| 405 | printk(BIOS_WARNING, "Warning: Pin %d should be smaller than" |
| 406 | " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS); |
| 407 | return -1; |
| 408 | } |
| 409 | /* Store (op (gpio_num), Local0) */ |
| 410 | acpigen_write_store(); |
| 411 | acpigen_soc_gpio_op(op, gpio_num); |
| 412 | acpigen_emit_byte(LOCAL0_OP); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | int acpigen_soc_read_rx_gpio(unsigned int gpio_num) |
| 417 | { |
| 418 | return acpigen_soc_get_gpio_state("\\_SB.GRXS", gpio_num); |
| 419 | } |
| 420 | |
| 421 | int acpigen_soc_get_tx_gpio(unsigned int gpio_num) |
| 422 | { |
| 423 | return acpigen_soc_get_gpio_state("\\_SB.GTXS", gpio_num); |
| 424 | } |
| 425 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 426 | int acpigen_soc_set_tx_gpio(unsigned int gpio_num) |
| 427 | { |
Eric Lai | 7cee566 | 2020-12-28 14:52:11 +0800 | [diff] [blame] | 428 | return acpigen_soc_gpio_op("\\_SB.STXS", gpio_num); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | int acpigen_soc_clear_tx_gpio(unsigned int gpio_num) |
| 432 | { |
Eric Lai | 7cee566 | 2020-12-28 14:52:11 +0800 | [diff] [blame] | 433 | return acpigen_soc_gpio_op("\\_SB.CTXS", gpio_num); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 434 | } |