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