Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2016 Intel Corp. |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 5 | * (Written by Lance Zhao <lijian.zhao@intel.com> for Intel Corp.) |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
Martin Roth | ebabfad | 2016-04-10 11:09:16 -0600 | [diff] [blame] | 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. |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <arch/acpi.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 19 | #include <arch/acpigen.h> |
Lance Zhao | 2fc82d6 | 2015-11-16 18:33:21 -0800 | [diff] [blame] | 20 | #include <arch/ioapic.h> |
| 21 | #include <arch/smp/mpspec.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 22 | #include <cbmem.h> |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 23 | #include <cpu/x86/smm.h> |
Aaron Durbin | 1ee6f0b | 2016-06-10 15:50:34 -0500 | [diff] [blame] | 24 | #include <cpu/cpu.h> |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 25 | #include <soc/acpi.h> |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 26 | #include <soc/intel/common/acpi.h> |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 27 | #include <soc/iomap.h> |
| 28 | #include <soc/pm.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 29 | #include <soc/nvs.h> |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 30 | #include <soc/pci_devs.h> |
Aaron Durbin | 9e81540 | 2016-09-13 12:31:57 -0500 | [diff] [blame^] | 31 | #include <string.h> |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 32 | #include "chip.h" |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 33 | |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 34 | #define CSTATE_RES(address_space, width, offset, address) \ |
| 35 | { \ |
| 36 | .space_id = address_space, \ |
| 37 | .bit_width = width, \ |
| 38 | .bit_offset = offset, \ |
| 39 | .addrl = address, \ |
| 40 | } |
| 41 | |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 42 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 43 | { |
Lance Zhao | 2c34e31 | 2015-11-16 18:13:23 -0800 | [diff] [blame] | 44 | /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */ |
| 45 | current += acpi_create_mcfg_mmconfig((void *) current, |
| 46 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, |
| 47 | 255); |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 48 | return current; |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 49 | } |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 50 | |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 51 | static int acpi_sci_irq(void) |
| 52 | { |
| 53 | int sci_irq = 9; |
| 54 | return sci_irq; |
| 55 | } |
| 56 | |
Lance Zhao | 2fc82d6 | 2015-11-16 18:33:21 -0800 | [diff] [blame] | 57 | static unsigned long acpi_madt_irq_overrides(unsigned long current) |
| 58 | { |
| 59 | int sci = acpi_sci_irq(); |
| 60 | uint16_t flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW;; |
| 61 | |
| 62 | /* INT_SRC_OVR */ |
| 63 | current += acpi_create_madt_irqoverride((void *)current, 0, 0, 2, 0); |
| 64 | |
| 65 | /* SCI */ |
| 66 | current += acpi_create_madt_irqoverride((void *)current, 0, sci, sci, flags); |
| 67 | |
| 68 | return current; |
| 69 | } |
| 70 | |
| 71 | unsigned long acpi_fill_madt(unsigned long current) |
| 72 | { |
| 73 | /* Local APICs */ |
| 74 | current = acpi_create_madt_lapics(current); |
| 75 | |
| 76 | /* IOAPIC */ |
| 77 | current += acpi_create_madt_ioapic((void *) current, |
| 78 | 2, IO_APIC_ADDR, 0); |
| 79 | |
| 80 | return acpi_madt_irq_overrides(current); |
| 81 | } |
| 82 | |
Aaron Durbin | c3ee3f6 | 2016-05-11 10:35:49 -0500 | [diff] [blame] | 83 | void acpi_fill_fadt(acpi_fadt_t * fadt) |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 84 | { |
| 85 | const uint16_t pmbase = ACPI_PMIO_BASE; |
| 86 | |
Aaron Durbin | c3ee3f6 | 2016-05-11 10:35:49 -0500 | [diff] [blame] | 87 | /* Use ACPI 5.0 revision. */ |
| 88 | fadt->header.revision = ACPI_FADT_REV_ACPI_5_0; |
| 89 | |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 90 | fadt->sci_int = acpi_sci_irq(); |
Hannah Williams | 6516422 | 2016-06-24 14:13:45 -0700 | [diff] [blame] | 91 | fadt->smi_cmd = APM_CNT; |
| 92 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 93 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 94 | |
| 95 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
| 96 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
| 97 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 98 | fadt->gpe0_blk = pmbase + GPE0_STS(0); |
| 99 | |
| 100 | fadt->pm1_evt_len = 4; |
| 101 | fadt->pm1_cnt_len = 2; |
| 102 | fadt->pm_tmr_len = 4; |
| 103 | /* There are 4 GPE0 STS/EN pairs each 32 bits wide. */ |
| 104 | fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t); |
| 105 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 106 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 107 | fadt->flush_size = 0x400; /* twice of cache size*/ |
| 108 | fadt->flush_stride = 0x10; /* Cache line width */ |
| 109 | fadt->duty_offset = 1; |
| 110 | fadt->duty_width = 3; |
| 111 | fadt->day_alrm = 0xd; |
| 112 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 113 | |
| 114 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 115 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 116 | ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE | |
| 117 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 118 | |
| 119 | fadt->reset_reg.space_id = 1; |
| 120 | fadt->reset_reg.bit_width = 8; |
| 121 | fadt->reset_reg.addrl = 0xcf9; |
| 122 | fadt->reset_value = 6; |
| 123 | |
| 124 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 125 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 126 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
| 127 | |
| 128 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 129 | |
| 130 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 131 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 132 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
| 133 | |
| 134 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 135 | |
| 136 | fadt->x_pm_tmr_blk.space_id = 1; |
| 137 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 138 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 139 | |
| 140 | fadt->x_gpe1_blk.space_id = 1; |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 141 | } |
Zhao, Lijian | 30461a9 | 2015-12-01 09:14:20 -0800 | [diff] [blame] | 142 | |
| 143 | unsigned long southbridge_write_acpi_tables(device_t device, |
| 144 | unsigned long current, |
| 145 | struct acpi_rsdp *rsdp) |
| 146 | { |
| 147 | return acpi_write_hpet(device, current, rsdp); |
| 148 | } |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 149 | |
| 150 | static void acpi_create_gnvs(struct global_nvs_t *gnvs) |
| 151 | { |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 152 | struct soc_intel_apollolake_config *cfg; |
| 153 | struct device *dev = NB_DEV_ROOT; |
| 154 | |
Aaron Durbin | 9e81540 | 2016-09-13 12:31:57 -0500 | [diff] [blame^] | 155 | /* Clear out GNVS. */ |
| 156 | memset(gnvs, 0, sizeof(*gnvs)); |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 157 | |
Furquan Shaikh | d01f5a0 | 2016-06-13 22:23:49 -0700 | [diff] [blame] | 158 | if (IS_ENABLED(CONFIG_CONSOLE_CBMEM)) |
| 159 | gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
| 160 | |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 161 | if (IS_ENABLED(CONFIG_CHROMEOS)) { |
| 162 | /* Initialize Verified Boot data */ |
| 163 | chromeos_init_vboot(&gnvs->chromeos); |
| 164 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 165 | } |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 166 | |
Shaunak Saha | 60b4618 | 2016-08-02 17:25:13 -0700 | [diff] [blame] | 167 | /* Set unknown wake source */ |
| 168 | gnvs->pm1i = ~0ULL; |
Aaron Durbin | 9e81540 | 2016-09-13 12:31:57 -0500 | [diff] [blame^] | 169 | |
| 170 | if (!dev || !dev->chip_info) { |
| 171 | printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n"); |
| 172 | return; |
| 173 | } |
| 174 | cfg = dev->chip_info; |
| 175 | |
| 176 | /* Enable DPTF based on mainboard configuration */ |
| 177 | gnvs->dpte = cfg->dptf_enable; |
Shaunak Saha | 60b4618 | 2016-08-02 17:25:13 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /* Save wake source information for calculating ACPI _SWS values */ |
| 181 | int soc_fill_acpi_wake(uint32_t *pm1, uint32_t **gpe0) |
| 182 | { |
| 183 | struct chipset_power_state *ps; |
| 184 | static uint32_t gpe0_sts[GPE0_REG_MAX]; |
| 185 | uint32_t pm1_en; |
| 186 | int i; |
| 187 | |
| 188 | ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 189 | if (ps == NULL) |
| 190 | return -1; |
| 191 | |
| 192 | /* |
| 193 | * PM1_EN to check the basic wake events which can happen through |
| 194 | * powerbtn or any other wake source like lidopen, key board press etc. |
| 195 | * WAK_STS bit is set when the system is in one of the sleep states |
| 196 | * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting |
| 197 | * this bit, the PMC will transition the system to the ON state and |
| 198 | * can only be set by hardware and can only be cleared by writing a one |
| 199 | * to this bit position. |
| 200 | */ |
| 201 | pm1_en = ps->pm1_en | WAK_STS | RTC_EN | PWRBTN_EN; |
| 202 | *pm1 = ps->pm1_sts & pm1_en; |
| 203 | |
| 204 | /* Mask off GPE0 status bits that are not enabled */ |
| 205 | *gpe0 = &gpe0_sts[0]; |
| 206 | for (i = 0; i < GPE0_REG_MAX; i++) |
| 207 | gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i]; |
| 208 | |
| 209 | return GPE0_REG_MAX; |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void southbridge_inject_dsdt(device_t device) |
| 213 | { |
| 214 | struct global_nvs_t *gnvs; |
| 215 | |
| 216 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 217 | |
| 218 | if (gnvs) { |
| 219 | acpi_create_gnvs(gnvs); |
| 220 | acpi_save_gnvs((uintptr_t)gnvs); |
Aaron Durbin | 1ee6f0b | 2016-06-10 15:50:34 -0500 | [diff] [blame] | 221 | /* And tell SMI about it */ |
| 222 | smm_setup_structures(gnvs, NULL, NULL); |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 223 | |
| 224 | /* Add it to DSDT. */ |
| 225 | acpigen_write_scope("\\"); |
| 226 | acpigen_write_name_dword("NVSA", (uintptr_t)gnvs); |
| 227 | acpigen_pop_len(); |
| 228 | } |
| 229 | } |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 230 | static acpi_cstate_t cstate_map[] = { |
| 231 | { |
| 232 | /* C1 */ |
| 233 | .ctype = 1, /* ACPI C1 */ |
| 234 | .latency = 1, |
| 235 | .power = 1000, |
| 236 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0), |
| 237 | }, |
| 238 | { |
| 239 | .ctype = 2, /* ACPI C2 */ |
| 240 | .latency = 50, |
| 241 | .power = 10, |
| 242 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415), |
| 243 | }, |
| 244 | { |
| 245 | .ctype = 3, /* ACPI C3 */ |
| 246 | .latency = 150, |
| 247 | .power = 10, |
| 248 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419), |
| 249 | } |
| 250 | }; |
| 251 | |
| 252 | acpi_cstate_t *soc_get_cstate_map(int *entries) |
| 253 | { |
| 254 | *entries = ARRAY_SIZE(cstate_map); |
| 255 | return cstate_map; |
| 256 | } |
| 257 | |
| 258 | uint16_t soc_get_acpi_base_address(void) |
| 259 | { |
| 260 | return ACPI_PMIO_BASE; |
| 261 | } |