Angel Pons | 3bd1e3d | 2020-04-05 15:47:17 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame^] | 4 | #include <acpi/acpi_gnvs.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpigen.h> |
robbie zhang | b45dde0 | 2015-10-01 17:21:33 -0700 | [diff] [blame] | 6 | #include <arch/cpu.h> |
Duncan Laurie | db54a67 | 2015-09-04 14:19:35 -0700 | [diff] [blame] | 7 | #include <arch/ioapic.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 8 | #include <arch/smp/mpspec.h> |
| 9 | #include <cbmem.h> |
| 10 | #include <console/console.h> |
| 11 | #include <cpu/x86/smm.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 12 | #include <cpu/x86/msr.h> |
| 13 | #include <cpu/x86/tsc.h> |
Matt Delco | 9084c3c | 2018-07-27 14:17:29 -0700 | [diff] [blame] | 14 | #include <cpu/intel/common/common.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 15 | #include <cpu/intel/turbo.h> |
| 16 | #include <ec/google/chromeec/ec.h> |
Barnali Sarkar | 0a203d1 | 2017-05-04 18:02:17 +0530 | [diff] [blame] | 17 | #include <intelblocks/cpulib.h> |
Ravi Sarawadi | 1483d1f | 2017-09-28 17:06:01 -0700 | [diff] [blame] | 18 | #include <intelblocks/lpc_lib.h> |
Pratik Prajapati | 418535e | 2017-10-11 16:12:21 -0700 | [diff] [blame] | 19 | #include <intelblocks/sgx.h> |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 20 | #include <intelblocks/uart.h> |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 21 | #include <intelblocks/systemagent.h> |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 22 | #include <soc/intel/common/acpi.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 23 | #include <soc/acpi.h> |
| 24 | #include <soc/cpu.h> |
| 25 | #include <soc/iomap.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 26 | #include <soc/msr.h> |
| 27 | #include <soc/pci_devs.h> |
| 28 | #include <soc/pm.h> |
Naresh G Solanki | a2d4062 | 2016-08-30 20:47:13 +0530 | [diff] [blame] | 29 | #include <soc/ramstage.h> |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 30 | #include <soc/systemagent.h> |
robbie zhang | b45dde0 | 2015-10-01 17:21:33 -0700 | [diff] [blame] | 31 | #include <string.h> |
| 32 | #include <types.h> |
| 33 | #include <vendorcode/google/chromeos/gnvs.h> |
Duncan Laurie | 3d3b76b | 2016-02-25 08:45:43 -0800 | [diff] [blame] | 34 | #include <wrdd.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 35 | #include <device/pci_ops.h> |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 36 | |
Elyes HAOUAS | c338507 | 2019-03-21 15:38:06 +0100 | [diff] [blame] | 37 | #include "chip.h" |
| 38 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 39 | /* |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 40 | * List of suported C-states in this processor. |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 41 | */ |
| 42 | enum { |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 43 | C_STATE_C0, /* 0 */ |
| 44 | C_STATE_C1, /* 1 */ |
| 45 | C_STATE_C1E, /* 2 */ |
| 46 | C_STATE_C3, /* 3 */ |
| 47 | C_STATE_C6_SHORT_LAT, /* 4 */ |
| 48 | C_STATE_C6_LONG_LAT, /* 5 */ |
| 49 | C_STATE_C7_SHORT_LAT, /* 6 */ |
| 50 | C_STATE_C7_LONG_LAT, /* 7 */ |
| 51 | C_STATE_C7S_SHORT_LAT, /* 8 */ |
| 52 | C_STATE_C7S_LONG_LAT, /* 9 */ |
| 53 | C_STATE_C8, /* 10 */ |
| 54 | C_STATE_C9, /* 11 */ |
| 55 | C_STATE_C10, /* 12 */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 56 | NUM_C_STATES |
| 57 | }; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 58 | #define MWAIT_RES(state, sub_state) \ |
| 59 | { \ |
| 60 | .addrl = (((state) << 4) | (sub_state)), \ |
| 61 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 62 | .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \ |
| 63 | .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \ |
| 64 | .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static acpi_cstate_t cstate_map[NUM_C_STATES] = { |
| 68 | [C_STATE_C0] = { }, |
| 69 | [C_STATE_C1] = { |
| 70 | .latency = 0, |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 71 | .power = C1_POWER, |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 72 | .resource = MWAIT_RES(0, 0), |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 73 | }, |
| 74 | [C_STATE_C1E] = { |
| 75 | .latency = 0, |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 76 | .power = C1_POWER, |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 77 | .resource = MWAIT_RES(0, 1), |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 78 | }, |
| 79 | [C_STATE_C3] = { |
| 80 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 81 | .power = C3_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 82 | .resource = MWAIT_RES(1, 0), |
| 83 | }, |
| 84 | [C_STATE_C6_SHORT_LAT] = { |
| 85 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 86 | .power = C6_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 87 | .resource = MWAIT_RES(2, 0), |
| 88 | }, |
| 89 | [C_STATE_C6_LONG_LAT] = { |
| 90 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 91 | .power = C6_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 92 | .resource = MWAIT_RES(2, 1), |
| 93 | }, |
| 94 | [C_STATE_C7_SHORT_LAT] = { |
| 95 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 96 | .power = C7_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 97 | .resource = MWAIT_RES(3, 0), |
| 98 | }, |
| 99 | [C_STATE_C7_LONG_LAT] = { |
| 100 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 101 | .power = C7_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 102 | .resource = MWAIT_RES(3, 1), |
| 103 | }, |
| 104 | [C_STATE_C7S_SHORT_LAT] = { |
| 105 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 106 | .power = C7_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 107 | .resource = MWAIT_RES(3, 2), |
| 108 | }, |
| 109 | [C_STATE_C7S_LONG_LAT] = { |
| 110 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 111 | .power = C7_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 112 | .resource = MWAIT_RES(3, 3), |
| 113 | }, |
| 114 | [C_STATE_C8] = { |
| 115 | .latency = C_STATE_LATENCY_FROM_LAT_REG(3), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 116 | .power = C8_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 117 | .resource = MWAIT_RES(4, 0), |
| 118 | }, |
| 119 | [C_STATE_C9] = { |
| 120 | .latency = C_STATE_LATENCY_FROM_LAT_REG(4), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 121 | .power = C9_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 122 | .resource = MWAIT_RES(5, 0), |
| 123 | }, |
| 124 | [C_STATE_C10] = { |
| 125 | .latency = C_STATE_LATENCY_FROM_LAT_REG(5), |
robbie zhang | c16b1fd | 2015-09-11 14:25:15 -0700 | [diff] [blame] | 126 | .power = C10_POWER, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 127 | .resource = MWAIT_RES(6, 0), |
| 128 | }, |
| 129 | }; |
| 130 | |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 131 | static int cstate_set_s0ix[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 132 | C_STATE_C1E, |
| 133 | C_STATE_C7S_LONG_LAT, |
| 134 | C_STATE_C10 |
| 135 | }; |
| 136 | |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 137 | static int cstate_set_non_s0ix[] = { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 138 | C_STATE_C1E, |
| 139 | C_STATE_C3, |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 140 | C_STATE_C7S_LONG_LAT, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | static int get_cores_per_package(void) |
| 144 | { |
| 145 | struct cpuinfo_x86 c; |
| 146 | struct cpuid_result result; |
| 147 | int cores = 1; |
| 148 | |
| 149 | get_fms(&c, cpuid_eax(1)); |
| 150 | if (c.x86 != 6) |
| 151 | return 1; |
| 152 | |
| 153 | result = cpuid_ext(0xb, 1); |
| 154 | cores = result.ebx & 0xff; |
| 155 | |
| 156 | return cores; |
| 157 | } |
| 158 | |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame^] | 159 | void acpi_create_gnvs(struct global_nvs *gnvs) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 160 | { |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 161 | const struct soc_intel_skylake_config *config = config_of_soc(); |
Duncan Laurie | 7fce30c | 2015-09-04 13:53:14 -0700 | [diff] [blame] | 162 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 163 | /* Set unknown wake source */ |
| 164 | gnvs->pm1i = -1; |
| 165 | |
| 166 | /* CPU core count */ |
| 167 | gnvs->pcnt = dev_count_cpu(); |
| 168 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 169 | #if CONFIG(CONSOLE_CBMEM) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 170 | /* Update the mem console pointer. */ |
| 171 | gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE); |
| 172 | #endif |
| 173 | |
Kyösti Mälkki | 000d91a | 2020-06-15 13:04:48 +0300 | [diff] [blame] | 174 | if (CONFIG(CHROMEOS)) { |
| 175 | /* Initialize Verified Boot data */ |
| 176 | chromeos_init_chromeos_acpi(&(gnvs->chromeos)); |
| 177 | if (CONFIG(EC_GOOGLE_CHROMEEC)) { |
| 178 | gnvs->chromeos.vbt2 = google_ec_running_ro() ? |
| 179 | ACTIVE_ECFW_RO : ACTIVE_ECFW_RW; |
| 180 | } else { |
| 181 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 182 | } |
| 183 | } |
Duncan Laurie | 7fce30c | 2015-09-04 13:53:14 -0700 | [diff] [blame] | 184 | |
| 185 | /* Enable DPTF based on mainboard configuration */ |
| 186 | gnvs->dpte = config->dptf_enable; |
Duncan Laurie | 3d3b76b | 2016-02-25 08:45:43 -0800 | [diff] [blame] | 187 | |
| 188 | /* Fill in the Wifi Region id */ |
| 189 | gnvs->cid1 = wifi_regulatory_domain(); |
Furquan Shaikh | 3bfe340 | 2016-10-18 14:25:25 -0700 | [diff] [blame] | 190 | |
| 191 | /* Set USB2/USB3 wake enable bitmaps. */ |
| 192 | gnvs->u2we = config->usb2_wake_enable_bitmap; |
| 193 | gnvs->u3we = config->usb3_wake_enable_bitmap; |
Pratik Prajapati | 418535e | 2017-10-11 16:12:21 -0700 | [diff] [blame] | 194 | |
Michael Niewöhner | 7736bfc | 2019-10-22 23:05:06 +0200 | [diff] [blame] | 195 | if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE)) |
Pratik Prajapati | 418535e | 2017-10-11 16:12:21 -0700 | [diff] [blame] | 196 | sgx_fill_gnvs(gnvs); |
Subrata Banik | b6df6b0 | 2020-01-03 15:29:02 +0530 | [diff] [blame] | 197 | |
| 198 | /* Fill in Above 4GB MMIO resource */ |
| 199 | sa_fill_gnvs(gnvs); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 202 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 203 | { |
| 204 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
Duncan Laurie | 50f06a1 | 2018-03-02 14:56:38 -0800 | [diff] [blame] | 205 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, |
Duncan Laurie | fd50b7c | 2018-03-02 14:47:11 -0800 | [diff] [blame] | 206 | (CONFIG_SA_PCIEX_LENGTH >> 20) - 1); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 207 | return current; |
| 208 | } |
| 209 | |
Duncan Laurie | db54a67 | 2015-09-04 14:19:35 -0700 | [diff] [blame] | 210 | unsigned long acpi_fill_madt(unsigned long current) |
| 211 | { |
| 212 | /* Local APICs */ |
| 213 | current = acpi_create_madt_lapics(current); |
| 214 | |
| 215 | /* IOAPIC */ |
| 216 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 217 | 2, IO_APIC_ADDR, 0); |
| 218 | |
| 219 | return acpi_madt_irq_overrides(current); |
| 220 | } |
| 221 | |
Duncan Laurie | 135c2c4 | 2016-10-17 19:47:51 -0700 | [diff] [blame] | 222 | void acpi_fill_fadt(acpi_fadt_t *fadt) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 223 | { |
| 224 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 225 | config_t *config = config_of_soc(); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 226 | |
Marc Jones | f9ea7ed | 2018-08-22 18:59:26 -0600 | [diff] [blame] | 227 | fadt->header.revision = get_acpi_table_revision(FADT); |
Duncan Laurie | 135c2c4 | 2016-10-17 19:47:51 -0700 | [diff] [blame] | 228 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 229 | fadt->sci_int = acpi_sci_irq(); |
Kyösti Mälkki | c328a68 | 2019-11-23 07:23:40 +0200 | [diff] [blame] | 230 | |
Kyösti Mälkki | 0a9e72e | 2019-08-11 01:22:28 +0300 | [diff] [blame] | 231 | if (permanent_smi_handler()) { |
Kyösti Mälkki | c328a68 | 2019-11-23 07:23:40 +0200 | [diff] [blame] | 232 | fadt->smi_cmd = APM_CNT; |
| 233 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 234 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
| 235 | } |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 236 | |
| 237 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
| 238 | fadt->pm1b_evt_blk = 0x0; |
| 239 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
| 240 | fadt->pm1b_cnt_blk = 0x0; |
| 241 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
Duncan Laurie | 662b6cb | 2018-01-30 09:58:07 -0800 | [diff] [blame] | 242 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 243 | fadt->gpe0_blk = pmbase + GPE0_STS(0); |
| 244 | fadt->gpe1_blk = 0; |
| 245 | |
| 246 | fadt->pm1_evt_len = 4; |
| 247 | fadt->pm1_cnt_len = 2; |
| 248 | fadt->pm2_cnt_len = 1; |
Duncan Laurie | 662b6cb | 2018-01-30 09:58:07 -0800 | [diff] [blame] | 249 | fadt->pm_tmr_len = 4; |
Aaron Durbin | 71e0ac8 | 2015-08-07 23:00:22 -0500 | [diff] [blame] | 250 | /* There are 4 GPE0 STS/EN pairs each 32 bits wide. */ |
| 251 | fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 252 | fadt->gpe1_blk_len = 0; |
| 253 | fadt->gpe1_base = 0; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 254 | fadt->p_lvl2_lat = 1; |
| 255 | fadt->p_lvl3_lat = 87; |
| 256 | fadt->flush_size = 1024; |
| 257 | fadt->flush_stride = 16; |
| 258 | fadt->duty_offset = 1; |
| 259 | fadt->duty_width = 0; |
| 260 | fadt->day_alrm = 0xd; |
| 261 | fadt->mon_alrm = 0x00; |
| 262 | fadt->century = 0x00; |
Paul Menzel | 8ca2af1 | 2019-02-08 15:19:20 +0100 | [diff] [blame] | 263 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_FREE; |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 264 | if (!CONFIG(NO_FADT_8042)) |
Jenny TC | 2864f85 | 2017-02-09 16:01:59 +0530 | [diff] [blame] | 265 | fadt->iapc_boot_arch |= ACPI_FADT_8042; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 266 | |
| 267 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 268 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 269 | ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE | |
| 270 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 271 | |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 272 | if (config->s0ix_enable) |
Haridhar Kalvala | 1cedc7e | 2018-06-07 10:52:31 +0530 | [diff] [blame] | 273 | fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0; |
| 274 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 275 | fadt->reset_reg.space_id = 1; |
| 276 | fadt->reset_reg.bit_width = 8; |
| 277 | fadt->reset_reg.bit_offset = 0; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 278 | fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 279 | fadt->reset_reg.addrl = 0xcf9; |
| 280 | fadt->reset_reg.addrh = 0; |
| 281 | fadt->reset_value = 6; |
| 282 | |
| 283 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 284 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 285 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 286 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 287 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
| 288 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 289 | |
| 290 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 291 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 292 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 293 | fadt->x_pm1b_evt_blk.access_size = 0; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 294 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 295 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 296 | |
| 297 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 298 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 299 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 300 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 301 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
| 302 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 303 | |
| 304 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 305 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 306 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 307 | fadt->x_pm1b_cnt_blk.access_size = 0; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 308 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 309 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 310 | |
| 311 | fadt->x_pm2_cnt_blk.space_id = 1; |
| 312 | fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8; |
| 313 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 314 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 315 | fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT; |
| 316 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 317 | |
Duncan Laurie | 662b6cb | 2018-01-30 09:58:07 -0800 | [diff] [blame] | 318 | fadt->x_pm_tmr_blk.space_id = 1; |
| 319 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 320 | fadt->x_pm_tmr_blk.bit_offset = 0; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 321 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
Duncan Laurie | 662b6cb | 2018-01-30 09:58:07 -0800 | [diff] [blame] | 322 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 323 | fadt->x_pm_tmr_blk.addrh = 0x0; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 324 | |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 325 | /* |
| 326 | * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5. |
| 327 | * The bit_width field intentionally overflows here. |
| 328 | * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which |
| 329 | * seems to work fine on Linux 5.0 and Windows 10. |
| 330 | */ |
| 331 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 332 | fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 333 | fadt->x_gpe0_blk.bit_offset = 0; |
Angel Pons | a23aff3 | 2020-06-21 20:47:54 +0200 | [diff] [blame] | 334 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 335 | fadt->x_gpe0_blk.addrl = fadt->gpe0_blk; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 336 | fadt->x_gpe0_blk.addrh = 0; |
| 337 | |
| 338 | fadt->x_gpe1_blk.space_id = 1; |
| 339 | fadt->x_gpe1_blk.bit_width = 0; |
| 340 | fadt->x_gpe1_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 341 | fadt->x_gpe1_blk.access_size = 0; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 342 | fadt->x_gpe1_blk.addrl = 0x0; |
| 343 | fadt->x_gpe1_blk.addrh = 0x0; |
| 344 | } |
| 345 | |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 346 | static void write_c_state_entries(acpi_cstate_t *map, const int *set, size_t max_c_state) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 347 | { |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 348 | for (size_t i = 0; i < max_c_state; i++) { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 349 | memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t)); |
| 350 | map[i].ctype = i + 1; |
| 351 | } |
| 352 | |
| 353 | /* Generate C-state tables */ |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 354 | acpigen_write_CST_package(map, max_c_state); |
| 355 | } |
| 356 | |
| 357 | static void generate_c_state_entries(int s0ix_enable) |
| 358 | { |
| 359 | if (s0ix_enable) { |
| 360 | acpi_cstate_t map[ARRAY_SIZE(cstate_set_s0ix)]; |
| 361 | write_c_state_entries(map, cstate_set_s0ix, ARRAY_SIZE(map)); |
| 362 | } else { |
| 363 | acpi_cstate_t map[ARRAY_SIZE(cstate_set_non_s0ix)]; |
| 364 | write_c_state_entries(map, cstate_set_non_s0ix, ARRAY_SIZE(map)); |
| 365 | } |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static int calculate_power(int tdp, int p1_ratio, int ratio) |
| 369 | { |
| 370 | u32 m; |
| 371 | u32 power; |
| 372 | |
| 373 | /* |
| 374 | * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2 |
| 375 | * |
| 376 | * Power = (ratio / p1_ratio) * m * tdp |
| 377 | */ |
| 378 | |
| 379 | m = (110000 - ((p1_ratio - ratio) * 625)) / 11; |
| 380 | m = (m * m) / 1000; |
| 381 | |
| 382 | power = ((ratio * 100000 / p1_ratio) / 100); |
| 383 | power *= (m / 100) * (tdp / 1000); |
| 384 | power /= 1000; |
| 385 | |
| 386 | return (int)power; |
| 387 | } |
| 388 | |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 389 | static void generate_p_state_entries(int core, int cores_per_package) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 390 | { |
| 391 | int ratio_min, ratio_max, ratio_turbo, ratio_step; |
| 392 | int coord_type, power_max, power_unit, num_entries; |
| 393 | int ratio, power, clock, clock_max; |
| 394 | msr_t msr; |
| 395 | |
| 396 | /* Determine P-state coordination type from MISC_PWR_MGMT[0] */ |
| 397 | msr = rdmsr(MSR_MISC_PWR_MGMT); |
| 398 | if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS) |
| 399 | coord_type = SW_ANY; |
| 400 | else |
| 401 | coord_type = HW_ALL; |
| 402 | |
| 403 | /* Get bus ratio limits and calculate clock speeds */ |
| 404 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 405 | ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */ |
| 406 | |
| 407 | /* Determine if this CPU has configurable TDP */ |
| 408 | if (cpu_config_tdp_levels()) { |
| 409 | /* Set max ratio to nominal TDP ratio */ |
| 410 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 411 | ratio_max = msr.lo & 0xff; |
| 412 | } else { |
| 413 | /* Max Non-Turbo Ratio */ |
| 414 | ratio_max = (msr.lo >> 8) & 0xff; |
| 415 | } |
Aamir Bohra | 1041d39 | 2017-06-02 11:56:14 +0530 | [diff] [blame] | 416 | clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 417 | |
| 418 | /* Calculate CPU TDP in mW */ |
| 419 | msr = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 420 | power_unit = 2 << ((msr.lo & 0xf) - 1); |
| 421 | msr = rdmsr(MSR_PKG_POWER_SKU); |
| 422 | power_max = ((msr.lo & 0x7fff) / power_unit) * 1000; |
| 423 | |
| 424 | /* Write _PCT indicating use of FFixedHW */ |
| 425 | acpigen_write_empty_PCT(); |
| 426 | |
| 427 | /* Write _PPC with no limit on supported P-state */ |
| 428 | acpigen_write_PPC_NVS(); |
| 429 | |
| 430 | /* Write PSD indicating configured coordination type */ |
| 431 | acpigen_write_PSD_package(core, 1, coord_type); |
| 432 | |
| 433 | /* Add P-state entries in _PSS table */ |
| 434 | acpigen_write_name("_PSS"); |
| 435 | |
| 436 | /* Determine ratio points */ |
| 437 | ratio_step = PSS_RATIO_STEP; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 438 | num_entries = ((ratio_max - ratio_min) / ratio_step) + 1; |
| 439 | if (num_entries > PSS_MAX_ENTRIES) { |
| 440 | ratio_step += 1; |
| 441 | num_entries = ((ratio_max - ratio_min) / ratio_step) + 1; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /* P[T] is Turbo state if enabled */ |
| 445 | if (get_turbo_state() == TURBO_ENABLED) { |
| 446 | /* _PSS package count including Turbo */ |
| 447 | acpigen_write_package(num_entries + 2); |
| 448 | |
| 449 | msr = rdmsr(MSR_TURBO_RATIO_LIMIT); |
| 450 | ratio_turbo = msr.lo & 0xff; |
| 451 | |
| 452 | /* Add entry for Turbo ratio */ |
| 453 | acpigen_write_PSS_package( |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 454 | clock_max + 1, /* MHz */ |
| 455 | power_max, /* mW */ |
| 456 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 457 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 458 | ratio_turbo << 8, /* control */ |
| 459 | ratio_turbo << 8); /* status */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 460 | } else { |
| 461 | /* _PSS package count without Turbo */ |
| 462 | acpigen_write_package(num_entries + 1); |
| 463 | } |
| 464 | |
| 465 | /* First regular entry is max non-turbo ratio */ |
| 466 | acpigen_write_PSS_package( |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 467 | clock_max, /* MHz */ |
| 468 | power_max, /* mW */ |
| 469 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 470 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 471 | ratio_max << 8, /* control */ |
| 472 | ratio_max << 8); /* status */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 473 | |
| 474 | /* Generate the remaining entries */ |
| 475 | for (ratio = ratio_min + ((num_entries - 1) * ratio_step); |
| 476 | ratio >= ratio_min; ratio -= ratio_step) { |
| 477 | |
| 478 | /* Calculate power at this ratio */ |
| 479 | power = calculate_power(power_max, ratio_max, ratio); |
Aamir Bohra | 1041d39 | 2017-06-02 11:56:14 +0530 | [diff] [blame] | 480 | clock = ratio * CONFIG_CPU_BCLK_MHZ; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 481 | |
| 482 | acpigen_write_PSS_package( |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 483 | clock, /* MHz */ |
| 484 | power, /* mW */ |
| 485 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 486 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 487 | ratio << 8, /* control */ |
| 488 | ratio << 8); /* status */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /* Fix package length */ |
| 492 | acpigen_pop_len(); |
| 493 | } |
| 494 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 495 | void generate_cpu_entries(const struct device *device) |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 496 | { |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 497 | int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS, plen = 6; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 498 | int totalcores = dev_count_cpu(); |
| 499 | int cores_per_package = get_cores_per_package(); |
| 500 | int numcpus = totalcores/cores_per_package; |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 501 | config_t *config = config_of_soc(); |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 502 | int is_s0ix_enable = config->s0ix_enable; |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 503 | |
| 504 | printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n", |
| 505 | numcpus, cores_per_package); |
| 506 | |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 507 | if (config->eist_enable && config->speed_shift_enable) { |
Matt Delco | 9084c3c | 2018-07-27 14:17:29 -0700 | [diff] [blame] | 508 | struct cppc_config cppc_config; |
| 509 | cpu_init_cppc_config(&cppc_config, 2 /* version 2 */); |
| 510 | acpigen_write_CPPC_package(&cppc_config); |
| 511 | } |
| 512 | |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 513 | for (cpu_id = 0; cpu_id < numcpus; cpu_id++) { |
| 514 | for (core_id = 0; core_id < cores_per_package; core_id++) { |
| 515 | if (core_id > 0) { |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 516 | pcontrol_blk = 0; |
| 517 | plen = 0; |
| 518 | } |
| 519 | |
Christian Walter | be3979c | 2019-12-18 15:07:59 +0100 | [diff] [blame] | 520 | /* Generate processor \_SB.CPUx */ |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 521 | acpigen_write_processor( |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 522 | cpu_id*cores_per_package+core_id, |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 523 | pcontrol_blk, plen); |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 524 | /* Generate C-state tables */ |
Jacob Garber | 9172b69 | 2019-06-26 16:18:16 -0600 | [diff] [blame] | 525 | generate_c_state_entries(is_s0ix_enable); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 526 | |
Matt Delco | 9084c3c | 2018-07-27 14:17:29 -0700 | [diff] [blame] | 527 | if (config->eist_enable) { |
Subrata Banik | 6b45ee4 | 2017-05-12 11:43:57 +0530 | [diff] [blame] | 528 | /* Generate P-state tables */ |
| 529 | generate_p_state_entries(core_id, |
| 530 | cores_per_package); |
Matt Delco | 9084c3c | 2018-07-27 14:17:29 -0700 | [diff] [blame] | 531 | if (config->speed_shift_enable) |
| 532 | acpigen_write_CPPC_method(); |
| 533 | } |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 534 | acpigen_pop_len(); |
| 535 | } |
| 536 | } |
Arthur Heymans | 8afc135 | 2018-11-28 12:07:19 +0100 | [diff] [blame] | 537 | |
| 538 | /* PPKG is usually used for thermal management |
| 539 | of the first and only package. */ |
| 540 | acpigen_write_processor_package("PPKG", 0, cores_per_package); |
| 541 | |
| 542 | /* Add a method to notify processor nodes */ |
| 543 | acpigen_write_processor_cnot(cores_per_package); |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 546 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 547 | { |
Kyösti Mälkki | 903b40a | 2019-07-03 07:25:59 +0300 | [diff] [blame] | 548 | struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD); |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 549 | const u32 gfx_vtbar = MCHBAR32(GFXVTBAR) & ~0xfff; |
| 550 | const bool gfxvten = MCHBAR32(GFXVTBAR) & 1; |
| 551 | |
| 552 | /* iGFX has to be enabled, GFXVTBAR set and in 32-bit space. */ |
| 553 | if (igfx_dev && igfx_dev->enabled && gfxvten && |
| 554 | gfx_vtbar && !MCHBAR32(GFXVTBAR + 4)) { |
Matt DeVillier | cbe73ea | 2018-06-25 14:40:53 -0500 | [diff] [blame] | 555 | unsigned long tmp = current; |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 556 | |
| 557 | current += acpi_create_dmar_drhd(current, 0, 0, gfx_vtbar); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 558 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 559 | |
| 560 | acpi_dmar_drhd_fixup(tmp, current); |
Matt DeVillier | cbe73ea | 2018-06-25 14:40:53 -0500 | [diff] [blame] | 561 | |
| 562 | /* Add RMRR entry */ |
| 563 | tmp = current; |
| 564 | |
| 565 | current += acpi_create_dmar_rmrr(current, 0, |
| 566 | sa_get_gsm_base(), sa_get_tolud_base() - 1); |
| 567 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 568 | acpi_dmar_rmrr_fixup(tmp, current); |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 571 | const u32 vtvc0bar = MCHBAR32(VTVC0BAR) & ~0xfff; |
| 572 | const bool vtvc0en = MCHBAR32(VTVC0BAR) & 1; |
| 573 | |
| 574 | /* General VTBAR has to be set and in 32-bit space. */ |
Angel Pons | ef879a8 | 2019-08-30 19:42:23 +0200 | [diff] [blame] | 575 | if (vtvc0bar && vtvc0en && !MCHBAR32(VTVC0BAR + 4)) { |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 576 | const unsigned long tmp = current; |
| 577 | |
Angel Pons | ef879a8 | 2019-08-30 19:42:23 +0200 | [diff] [blame] | 578 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar); |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 579 | |
Angel Pons | ef879a8 | 2019-08-30 19:42:23 +0200 | [diff] [blame] | 580 | current += acpi_create_dmar_ds_ioapic(current, 2, V_P2SB_IBDF_BUS, |
| 581 | V_P2SB_IBDF_DEV, V_P2SB_IBDF_FUN); |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 582 | |
Angel Pons | ef879a8 | 2019-08-30 19:42:23 +0200 | [diff] [blame] | 583 | current += acpi_create_dmar_ds_msi_hpet(current, 0, V_P2SB_HBDF_BUS, |
| 584 | V_P2SB_HBDF_DEV, V_P2SB_HBDF_FUN); |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 585 | |
| 586 | acpi_dmar_drhd_fixup(tmp, current); |
| 587 | } |
| 588 | |
| 589 | return current; |
| 590 | } |
| 591 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 592 | unsigned long northbridge_write_acpi_tables(const struct device *const dev, |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 593 | unsigned long current, |
| 594 | struct acpi_rsdp *const rsdp) |
| 595 | { |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 596 | const struct soc_intel_skylake_config *const config = config_of(dev); |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 597 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 598 | |
| 599 | /* Create DMAR table only if we have VT-d capability. */ |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 600 | if (config->ignore_vtd || !soc_is_vtd_capable()) |
Nico Huber | c37b0e3 | 2017-09-18 20:03:46 +0200 | [diff] [blame] | 601 | return current; |
| 602 | |
| 603 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 604 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 605 | current += dmar->header.length; |
| 606 | current = acpi_align_current(current); |
| 607 | acpi_add_table(rsdp, dmar); |
| 608 | |
| 609 | return current; |
| 610 | } |
| 611 | |
Lee Leahy | b000513 | 2015-05-12 18:19:47 -0700 | [diff] [blame] | 612 | unsigned long acpi_madt_irq_overrides(unsigned long current) |
| 613 | { |
| 614 | int sci = acpi_sci_irq(); |
| 615 | acpi_madt_irqoverride_t *irqovr; |
| 616 | uint16_t flags = MP_IRQ_TRIGGER_LEVEL; |
| 617 | |
| 618 | /* INT_SRC_OVR */ |
| 619 | irqovr = (void *)current; |
| 620 | current += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0); |
| 621 | |
| 622 | if (sci >= 20) |
| 623 | flags |= MP_IRQ_POLARITY_LOW; |
| 624 | else |
| 625 | flags |= MP_IRQ_POLARITY_HIGH; |
| 626 | |
| 627 | /* SCI */ |
| 628 | irqovr = (void *)current; |
| 629 | current += acpi_create_madt_irqoverride(irqovr, 0, sci, sci, flags); |
| 630 | |
| 631 | return current; |
| 632 | } |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 633 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 634 | unsigned long southbridge_write_acpi_tables(const struct device *device, |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 635 | unsigned long current, |
| 636 | struct acpi_rsdp *rsdp) |
| 637 | { |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 638 | current = acpi_write_dbg2_pci_uart(rsdp, current, |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 639 | uart_get_device(), |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 640 | ACPI_ACCESS_SIZE_DWORD_ACCESS); |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 641 | current = acpi_write_hpet(device, current, rsdp); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 642 | return acpi_align_current(current); |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Furquan Shaikh | 338fd9a | 2020-04-24 22:57:05 -0700 | [diff] [blame] | 645 | void southbridge_inject_dsdt(const struct device *device) |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 646 | { |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame^] | 647 | struct global_nvs *gnvs; |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 648 | |
| 649 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 650 | if (!gnvs) { |
Lee Leahy | f4c4ab9 | 2017-03-16 17:08:03 -0700 | [diff] [blame] | 651 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs)); |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 652 | if (gnvs) |
| 653 | memset(gnvs, 0, sizeof(*gnvs)); |
| 654 | } |
| 655 | |
| 656 | if (gnvs) { |
| 657 | acpi_create_gnvs(gnvs); |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 658 | /* And tell SMI about it */ |
Kyösti Mälkki | c3c5521 | 2020-06-17 10:34:26 +0300 | [diff] [blame] | 659 | apm_control(APM_CNT_GNVS_UPDATE); |
Lee Leahy | 1d14b3e | 2015-05-12 18:23:27 -0700 | [diff] [blame] | 660 | |
| 661 | /* Add it to DSDT. */ |
| 662 | acpigen_write_scope("\\"); |
| 663 | acpigen_write_name_dword("NVSA", (u32) gnvs); |
| 664 | acpigen_pop_len(); |
| 665 | } |
| 666 | } |
| 667 | |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 668 | /* Save wake source information for calculating ACPI _SWS values */ |
| 669 | int soc_fill_acpi_wake(uint32_t *pm1, uint32_t **gpe0) |
| 670 | { |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 671 | const struct soc_intel_skylake_config *config = config_of_soc(); |
Naresh G Solanki | a1b3547 | 2015-12-11 18:13:02 +0530 | [diff] [blame] | 672 | struct chipset_power_state *ps; |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 673 | static uint32_t gpe0_sts[GPE0_REG_MAX]; |
| 674 | uint32_t pm1_en; |
Duncan Laurie | 95f9020 | 2016-10-25 20:07:22 -0700 | [diff] [blame] | 675 | uint32_t gpe0_std; |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 676 | int i; |
Aaron Durbin | 64606ce | 2016-10-27 09:53:17 -0500 | [diff] [blame] | 677 | const int last_index = GPE0_REG_MAX - 1; |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 678 | |
Naresh G Solanki | a1b3547 | 2015-12-11 18:13:02 +0530 | [diff] [blame] | 679 | ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 680 | if (ps == NULL) |
| 681 | return -1; |
| 682 | |
Duncan Laurie | 95f9020 | 2016-10-25 20:07:22 -0700 | [diff] [blame] | 683 | pm1_en = ps->pm1_en; |
| 684 | gpe0_std = ps->gpe0_en[3]; |
| 685 | |
| 686 | /* |
| 687 | * Chipset state in the suspend well (but not RTC) is lost in Deep S3 |
| 688 | * so enable Deep S3 wake events that are configured by the mainboard |
| 689 | */ |
Duncan Laurie | 1fe32d6 | 2017-04-10 21:02:13 -0700 | [diff] [blame] | 690 | if (ps->prev_sleep_state == ACPI_S3 && |
| 691 | (config->deep_s3_enable_ac || config->deep_s3_enable_dc)) { |
Duncan Laurie | 95f9020 | 2016-10-25 20:07:22 -0700 | [diff] [blame] | 692 | pm1_en |= PWRBTN_STS; /* Always enabled as wake source */ |
| 693 | if (config->deep_sx_config & DSX_EN_LAN_WAKE_PIN) |
| 694 | gpe0_std |= LAN_WAK_EN; |
| 695 | if (config->deep_sx_config & DSX_EN_WAKE_PIN) |
| 696 | pm1_en |= PCIEXPWAK_STS; |
| 697 | } |
| 698 | |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 699 | *pm1 = ps->pm1_sts & pm1_en; |
| 700 | |
| 701 | /* Mask off GPE0 status bits that are not enabled */ |
| 702 | *gpe0 = &gpe0_sts[0]; |
Aaron Durbin | 64606ce | 2016-10-27 09:53:17 -0500 | [diff] [blame] | 703 | for (i = 0; i < last_index; i++) |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 704 | gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i]; |
Aaron Durbin | 64606ce | 2016-10-27 09:53:17 -0500 | [diff] [blame] | 705 | gpe0_sts[last_index] = ps->gpe0_sts[last_index] & gpe0_std; |
Duncan Laurie | a1c8b34d | 2015-09-08 16:12:44 -0700 | [diff] [blame] | 706 | |
| 707 | return GPE0_REG_MAX; |
| 708 | } |
| 709 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 710 | const char *soc_acpi_name(const struct device *dev) |
Naresh G Solanki | a2d4062 | 2016-08-30 20:47:13 +0530 | [diff] [blame] | 711 | { |
| 712 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 713 | return "PCI0"; |
| 714 | |
Duncan Laurie | bf713b0 | 2018-05-07 15:33:18 -0700 | [diff] [blame] | 715 | if (dev->path.type == DEVICE_PATH_USB) { |
| 716 | switch (dev->path.usb.port_type) { |
| 717 | case 0: |
| 718 | /* Root Hub */ |
| 719 | return "RHUB"; |
| 720 | case 2: |
| 721 | /* USB2 ports */ |
| 722 | switch (dev->path.usb.port_id) { |
| 723 | case 0: return "HS01"; |
| 724 | case 1: return "HS02"; |
| 725 | case 2: return "HS03"; |
| 726 | case 3: return "HS04"; |
| 727 | case 4: return "HS05"; |
| 728 | case 5: return "HS06"; |
| 729 | case 6: return "HS07"; |
| 730 | case 7: return "HS08"; |
| 731 | case 8: return "HS09"; |
| 732 | case 9: return "HS10"; |
| 733 | } |
| 734 | break; |
| 735 | case 3: |
| 736 | /* USB3 ports */ |
| 737 | switch (dev->path.usb.port_id) { |
| 738 | case 0: return "SS01"; |
| 739 | case 1: return "SS02"; |
| 740 | case 2: return "SS03"; |
| 741 | case 3: return "SS04"; |
| 742 | case 4: return "SS05"; |
| 743 | case 5: return "SS06"; |
| 744 | } |
| 745 | break; |
| 746 | } |
| 747 | return NULL; |
| 748 | } |
| 749 | |
Naresh G Solanki | a2d4062 | 2016-08-30 20:47:13 +0530 | [diff] [blame] | 750 | if (dev->path.type != DEVICE_PATH_PCI) |
| 751 | return NULL; |
| 752 | |
Patrick Rudolph | 45ffee8 | 2019-09-26 14:45:29 +0200 | [diff] [blame] | 753 | /* Only match devices on the root bus */ |
| 754 | if (dev->bus && dev->bus->secondary > 0) |
| 755 | return NULL; |
| 756 | |
Naresh G Solanki | a2d4062 | 2016-08-30 20:47:13 +0530 | [diff] [blame] | 757 | switch (dev->path.pci.devfn) { |
| 758 | case SA_DEVFN_ROOT: return "MCHC"; |
| 759 | case SA_DEVFN_IGD: return "GFX0"; |
| 760 | case PCH_DEVFN_ISH: return "ISHB"; |
| 761 | case PCH_DEVFN_XHCI: return "XHCI"; |
| 762 | case PCH_DEVFN_USBOTG: return "XDCI"; |
| 763 | case PCH_DEVFN_THERMAL: return "THRM"; |
| 764 | case PCH_DEVFN_CIO: return "ICIO"; |
| 765 | case PCH_DEVFN_I2C0: return "I2C0"; |
| 766 | case PCH_DEVFN_I2C1: return "I2C1"; |
| 767 | case PCH_DEVFN_I2C2: return "I2C2"; |
| 768 | case PCH_DEVFN_I2C3: return "I2C3"; |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 769 | case PCH_DEVFN_CSE: return "CSE1"; |
| 770 | case PCH_DEVFN_CSE_2: return "CSE2"; |
| 771 | case PCH_DEVFN_CSE_IDER: return "CSED"; |
| 772 | case PCH_DEVFN_CSE_KT: return "CSKT"; |
| 773 | case PCH_DEVFN_CSE_3: return "CSE3"; |
Naresh G Solanki | a2d4062 | 2016-08-30 20:47:13 +0530 | [diff] [blame] | 774 | case PCH_DEVFN_SATA: return "SATA"; |
| 775 | case PCH_DEVFN_UART2: return "UAR2"; |
| 776 | case PCH_DEVFN_I2C4: return "I2C4"; |
| 777 | case PCH_DEVFN_I2C5: return "I2C5"; |
| 778 | case PCH_DEVFN_PCIE1: return "RP01"; |
| 779 | case PCH_DEVFN_PCIE2: return "RP02"; |
| 780 | case PCH_DEVFN_PCIE3: return "RP03"; |
| 781 | case PCH_DEVFN_PCIE4: return "RP04"; |
| 782 | case PCH_DEVFN_PCIE5: return "RP05"; |
| 783 | case PCH_DEVFN_PCIE6: return "RP06"; |
| 784 | case PCH_DEVFN_PCIE7: return "RP07"; |
| 785 | case PCH_DEVFN_PCIE8: return "RP08"; |
| 786 | case PCH_DEVFN_PCIE9: return "RP09"; |
| 787 | case PCH_DEVFN_PCIE10: return "RP10"; |
| 788 | case PCH_DEVFN_PCIE11: return "RP11"; |
| 789 | case PCH_DEVFN_PCIE12: return "RP12"; |
Maxim Polyakov | c6f2b61 | 2019-08-23 15:22:21 +0300 | [diff] [blame] | 790 | case PCH_DEVFN_PCIE13: return "RP13"; |
| 791 | case PCH_DEVFN_PCIE14: return "RP14"; |
| 792 | case PCH_DEVFN_PCIE15: return "RP15"; |
| 793 | case PCH_DEVFN_PCIE16: return "RP16"; |
Naresh G Solanki | a2d4062 | 2016-08-30 20:47:13 +0530 | [diff] [blame] | 794 | case PCH_DEVFN_UART0: return "UAR0"; |
| 795 | case PCH_DEVFN_UART1: return "UAR1"; |
| 796 | case PCH_DEVFN_GSPI0: return "SPI0"; |
| 797 | case PCH_DEVFN_GSPI1: return "SPI1"; |
| 798 | case PCH_DEVFN_EMMC: return "EMMC"; |
| 799 | case PCH_DEVFN_SDIO: return "SDIO"; |
| 800 | case PCH_DEVFN_SDCARD: return "SDXC"; |
| 801 | case PCH_DEVFN_LPC: return "LPCB"; |
| 802 | case PCH_DEVFN_P2SB: return "P2SB"; |
| 803 | case PCH_DEVFN_PMC: return "PMC_"; |
| 804 | case PCH_DEVFN_HDA: return "HDAS"; |
| 805 | case PCH_DEVFN_SMBUS: return "SBUS"; |
| 806 | case PCH_DEVFN_SPI: return "FSPI"; |
| 807 | case PCH_DEVFN_GBE: return "IGBE"; |
| 808 | case PCH_DEVFN_TRACEHUB:return "THUB"; |
| 809 | } |
| 810 | |
| 811 | return NULL; |
| 812 | } |
Furquan Shaikh | a6f0b27 | 2017-05-23 11:53:47 -0700 | [diff] [blame] | 813 | |
| 814 | static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num) |
| 815 | { |
| 816 | /* op (gpio_num) */ |
| 817 | acpigen_emit_namestring(op); |
| 818 | acpigen_write_integer(gpio_num); |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num) |
| 823 | { |
| 824 | /* Store (op (gpio_num), Local0) */ |
| 825 | acpigen_write_store(); |
| 826 | acpigen_soc_gpio_op(op, gpio_num); |
| 827 | acpigen_emit_byte(LOCAL0_OP); |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | int acpigen_soc_read_rx_gpio(unsigned int gpio_num) |
| 832 | { |
| 833 | return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num); |
| 834 | } |
| 835 | |
| 836 | int acpigen_soc_get_tx_gpio(unsigned int gpio_num) |
| 837 | { |
| 838 | return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num); |
| 839 | } |
| 840 | |
| 841 | int acpigen_soc_set_tx_gpio(unsigned int gpio_num) |
| 842 | { |
| 843 | return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num); |
| 844 | } |
| 845 | |
| 846 | int acpigen_soc_clear_tx_gpio(unsigned int gpio_num) |
| 847 | { |
| 848 | return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num); |
| 849 | } |