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