Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Subrata Banik | b6df6b0 | 2020-01-03 15:29:02 +0530 | [diff] [blame^] | 4 | * Copyright (C) 2019-2020 Intel Corp. |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpi.h> |
| 17 | #include <arch/acpigen.h> |
| 18 | #include <device/mmio.h> |
| 19 | #include <arch/smp/mpspec.h> |
| 20 | #include <cbmem.h> |
| 21 | #include <ec/google/chromeec/ec.h> |
| 22 | #include <intelblocks/cpulib.h> |
| 23 | #include <intelblocks/pmclib.h> |
| 24 | #include <intelblocks/acpi.h> |
| 25 | #include <soc/cpu.h> |
| 26 | #include <soc/iomap.h> |
| 27 | #include <soc/nvs.h> |
| 28 | #include <soc/pci_devs.h> |
| 29 | #include <soc/pm.h> |
| 30 | #include <soc/soc_chip.h> |
Subrata Banik | b6df6b0 | 2020-01-03 15:29:02 +0530 | [diff] [blame^] | 31 | #include <soc/systemagent.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 32 | #include <string.h> |
| 33 | #include <wrdd.h> |
| 34 | |
| 35 | /* |
| 36 | * List of supported C-states in this processor. |
| 37 | */ |
| 38 | enum { |
| 39 | C_STATE_C0, /* 0 */ |
| 40 | C_STATE_C1, /* 1 */ |
| 41 | C_STATE_C1E, /* 2 */ |
| 42 | C_STATE_C6_SHORT_LAT, /* 3 */ |
| 43 | C_STATE_C6_LONG_LAT, /* 4 */ |
| 44 | C_STATE_C7_SHORT_LAT, /* 5 */ |
| 45 | C_STATE_C7_LONG_LAT, /* 6 */ |
| 46 | C_STATE_C7S_SHORT_LAT, /* 7 */ |
| 47 | C_STATE_C7S_LONG_LAT, /* 8 */ |
| 48 | C_STATE_C8, /* 9 */ |
| 49 | C_STATE_C9, /* 10 */ |
| 50 | C_STATE_C10, /* 11 */ |
| 51 | NUM_C_STATES |
| 52 | }; |
| 53 | |
| 54 | #define MWAIT_RES(state, sub_state) \ |
| 55 | { \ |
| 56 | .addrl = (((state) << 4) | (sub_state)), \ |
| 57 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 58 | .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \ |
| 59 | .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \ |
| 60 | .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \ |
| 61 | } |
| 62 | |
| 63 | static const acpi_cstate_t cstate_map[NUM_C_STATES] = { |
| 64 | [C_STATE_C0] = {}, |
| 65 | [C_STATE_C1] = { |
| 66 | .latency = 0, |
| 67 | .power = C1_POWER, |
| 68 | .resource = MWAIT_RES(0, 0), |
| 69 | }, |
| 70 | [C_STATE_C1E] = { |
| 71 | .latency = 0, |
| 72 | .power = C1_POWER, |
| 73 | .resource = MWAIT_RES(0, 1), |
| 74 | }, |
| 75 | [C_STATE_C6_SHORT_LAT] = { |
| 76 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 77 | .power = C6_POWER, |
| 78 | .resource = MWAIT_RES(2, 0), |
| 79 | }, |
| 80 | [C_STATE_C6_LONG_LAT] = { |
| 81 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 82 | .power = C6_POWER, |
| 83 | .resource = MWAIT_RES(2, 1), |
| 84 | }, |
| 85 | [C_STATE_C7_SHORT_LAT] = { |
| 86 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 87 | .power = C7_POWER, |
| 88 | .resource = MWAIT_RES(3, 0), |
| 89 | }, |
| 90 | [C_STATE_C7_LONG_LAT] = { |
| 91 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 92 | .power = C7_POWER, |
| 93 | .resource = MWAIT_RES(3, 1), |
| 94 | }, |
| 95 | [C_STATE_C7S_SHORT_LAT] = { |
| 96 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 97 | .power = C7_POWER, |
| 98 | .resource = MWAIT_RES(3, 2), |
| 99 | }, |
| 100 | [C_STATE_C7S_LONG_LAT] = { |
| 101 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 102 | .power = C7_POWER, |
| 103 | .resource = MWAIT_RES(3, 3), |
| 104 | }, |
| 105 | [C_STATE_C8] = { |
| 106 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 107 | .power = C8_POWER, |
| 108 | .resource = MWAIT_RES(4, 0), |
| 109 | }, |
| 110 | [C_STATE_C9] = { |
| 111 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 112 | .power = C9_POWER, |
| 113 | .resource = MWAIT_RES(5, 0), |
| 114 | }, |
| 115 | [C_STATE_C10] = { |
| 116 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 117 | .power = C10_POWER, |
| 118 | .resource = MWAIT_RES(6, 0), |
| 119 | }, |
| 120 | }; |
| 121 | |
| 122 | static int cstate_set_non_s0ix[] = { |
| 123 | C_STATE_C1E, |
| 124 | C_STATE_C6_LONG_LAT, |
| 125 | C_STATE_C7S_LONG_LAT |
| 126 | }; |
| 127 | |
| 128 | static int cstate_set_s0ix[] = { |
| 129 | C_STATE_C1E, |
| 130 | C_STATE_C7S_LONG_LAT, |
| 131 | C_STATE_C10 |
| 132 | }; |
| 133 | |
| 134 | acpi_cstate_t *soc_get_cstate_map(size_t *entries) |
| 135 | { |
| 136 | static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix), |
| 137 | ARRAY_SIZE(cstate_set_non_s0ix))]; |
| 138 | int *set; |
| 139 | int i; |
| 140 | |
| 141 | config_t *config = config_of_soc(); |
| 142 | |
| 143 | int is_s0ix_enable = config->s0ix_enable; |
| 144 | |
| 145 | if (is_s0ix_enable) { |
| 146 | *entries = ARRAY_SIZE(cstate_set_s0ix); |
| 147 | set = cstate_set_s0ix; |
| 148 | } else { |
| 149 | *entries = ARRAY_SIZE(cstate_set_non_s0ix); |
| 150 | set = cstate_set_non_s0ix; |
| 151 | } |
| 152 | |
| 153 | for (i = 0; i < *entries; i++) { |
| 154 | memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t)); |
| 155 | map[i].ctype = i + 1; |
| 156 | } |
| 157 | return map; |
| 158 | } |
| 159 | |
| 160 | void soc_power_states_generation(int core_id, int cores_per_package) |
| 161 | { |
| 162 | config_t *config = config_of_soc(); |
| 163 | |
| 164 | if (config->eist_enable) |
| 165 | /* Generate P-state tables */ |
| 166 | generate_p_state_entries(core_id, cores_per_package); |
| 167 | } |
| 168 | |
| 169 | void soc_fill_fadt(acpi_fadt_t *fadt) |
| 170 | { |
| 171 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
| 172 | |
| 173 | config_t *config = config_of_soc(); |
| 174 | |
Meera Ravindranath | 48c7870 | 2019-12-12 10:37:49 +0530 | [diff] [blame] | 175 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 176 | fadt->pm_tmr_len = 4; |
| 177 | fadt->x_pm_tmr_blk.space_id = 1; |
| 178 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 179 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 180 | fadt->x_pm_tmr_blk.access_size = 0; |
| 181 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 182 | fadt->x_pm_tmr_blk.addrh = 0x0; |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 183 | |
| 184 | if (config->s0ix_enable) |
| 185 | fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0; |
| 186 | } |
| 187 | |
| 188 | uint32_t soc_read_sci_irq_select(void) |
| 189 | { |
| 190 | uintptr_t pmc_bar = soc_read_pmc_base(); |
| 191 | return read32((void *)pmc_bar + IRQ_REG); |
| 192 | } |
| 193 | |
| 194 | void acpi_create_gnvs(struct global_nvs_t *gnvs) |
| 195 | { |
| 196 | config_t *config = config_of_soc(); |
| 197 | |
| 198 | /* Set unknown wake source */ |
| 199 | gnvs->pm1i = -1; |
| 200 | |
| 201 | /* CPU core count */ |
| 202 | gnvs->pcnt = dev_count_cpu(); |
| 203 | |
| 204 | if (CONFIG(CONSOLE_CBMEM)) |
| 205 | /* Update the mem console pointer. */ |
| 206 | gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
| 207 | |
| 208 | if (CONFIG(CHROMEOS)) { |
| 209 | /* Initialize Verified Boot data */ |
| 210 | chromeos_init_chromeos_acpi(&(gnvs->chromeos)); |
| 211 | if (CONFIG(EC_GOOGLE_CHROMEEC)) { |
| 212 | gnvs->chromeos.vbt2 = google_ec_running_ro() ? |
| 213 | ACTIVE_ECFW_RO : ACTIVE_ECFW_RW; |
| 214 | } else |
| 215 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 216 | } |
| 217 | |
| 218 | /* Enable DPTF based on mainboard configuration */ |
| 219 | gnvs->dpte = config->dptf_enable; |
| 220 | |
| 221 | /* Fill in the Wifi Region id */ |
| 222 | gnvs->cid1 = wifi_regulatory_domain(); |
| 223 | |
| 224 | /* Set USB2/USB3 wake enable bitmaps. */ |
| 225 | gnvs->u2we = config->usb2_wake_enable_bitmap; |
| 226 | gnvs->u3we = config->usb3_wake_enable_bitmap; |
Subrata Banik | b6df6b0 | 2020-01-03 15:29:02 +0530 | [diff] [blame^] | 227 | |
| 228 | /* Fill in Above 4GB MMIO resource */ |
| 229 | sa_fill_gnvs(gnvs); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en, |
| 233 | const struct chipset_power_state *ps) |
| 234 | { |
| 235 | /* |
| 236 | * WAK_STS bit is set when the system is in one of the sleep states |
| 237 | * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting |
| 238 | * this bit, the PMC will transition the system to the ON state and |
| 239 | * can only be set by hardware and can only be cleared by writing a one |
| 240 | * to this bit position. |
| 241 | */ |
| 242 | |
| 243 | generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN; |
| 244 | return generic_pm1_en; |
| 245 | } |
| 246 | |
| 247 | int soc_madt_sci_irq_polarity(int sci) |
| 248 | { |
| 249 | return MP_IRQ_POLARITY_HIGH; |
| 250 | } |