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> |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 30 | |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 31 | #define CSTATE_RES(address_space, width, offset, address) \ |
| 32 | { \ |
| 33 | .space_id = address_space, \ |
| 34 | .bit_width = width, \ |
| 35 | .bit_offset = offset, \ |
| 36 | .addrl = address, \ |
| 37 | } |
| 38 | |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 39 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 40 | { |
Lance Zhao | 2c34e31 | 2015-11-16 18:13:23 -0800 | [diff] [blame] | 41 | /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */ |
| 42 | current += acpi_create_mcfg_mmconfig((void *) current, |
| 43 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, |
| 44 | 255); |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 45 | return current; |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 46 | } |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 47 | |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 48 | static int acpi_sci_irq(void) |
| 49 | { |
| 50 | int sci_irq = 9; |
| 51 | return sci_irq; |
| 52 | } |
| 53 | |
Lance Zhao | 2fc82d6 | 2015-11-16 18:33:21 -0800 | [diff] [blame] | 54 | static unsigned long acpi_madt_irq_overrides(unsigned long current) |
| 55 | { |
| 56 | int sci = acpi_sci_irq(); |
| 57 | uint16_t flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW;; |
| 58 | |
| 59 | /* INT_SRC_OVR */ |
| 60 | current += acpi_create_madt_irqoverride((void *)current, 0, 0, 2, 0); |
| 61 | |
| 62 | /* SCI */ |
| 63 | current += acpi_create_madt_irqoverride((void *)current, 0, sci, sci, flags); |
| 64 | |
| 65 | return current; |
| 66 | } |
| 67 | |
| 68 | unsigned long acpi_fill_madt(unsigned long current) |
| 69 | { |
| 70 | /* Local APICs */ |
| 71 | current = acpi_create_madt_lapics(current); |
| 72 | |
| 73 | /* IOAPIC */ |
| 74 | current += acpi_create_madt_ioapic((void *) current, |
| 75 | 2, IO_APIC_ADDR, 0); |
| 76 | |
| 77 | return acpi_madt_irq_overrides(current); |
| 78 | } |
| 79 | |
Aaron Durbin | c3ee3f6 | 2016-05-11 10:35:49 -0500 | [diff] [blame] | 80 | void acpi_fill_fadt(acpi_fadt_t * fadt) |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 81 | { |
| 82 | const uint16_t pmbase = ACPI_PMIO_BASE; |
| 83 | |
Aaron Durbin | c3ee3f6 | 2016-05-11 10:35:49 -0500 | [diff] [blame] | 84 | /* Use ACPI 5.0 revision. */ |
| 85 | fadt->header.revision = ACPI_FADT_REV_ACPI_5_0; |
| 86 | |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 87 | fadt->sci_int = acpi_sci_irq(); |
Hannah Williams | 6516422 | 2016-06-24 14:13:45 -0700 | [diff] [blame^] | 88 | fadt->smi_cmd = APM_CNT; |
| 89 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 90 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 91 | |
| 92 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
| 93 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
| 94 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 95 | fadt->gpe0_blk = pmbase + GPE0_STS(0); |
| 96 | |
| 97 | fadt->pm1_evt_len = 4; |
| 98 | fadt->pm1_cnt_len = 2; |
| 99 | fadt->pm_tmr_len = 4; |
| 100 | /* There are 4 GPE0 STS/EN pairs each 32 bits wide. */ |
| 101 | fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t); |
| 102 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 103 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 104 | fadt->flush_size = 0x400; /* twice of cache size*/ |
| 105 | fadt->flush_stride = 0x10; /* Cache line width */ |
| 106 | fadt->duty_offset = 1; |
| 107 | fadt->duty_width = 3; |
| 108 | fadt->day_alrm = 0xd; |
| 109 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 110 | |
| 111 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 112 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 113 | ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE | |
| 114 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 115 | |
| 116 | fadt->reset_reg.space_id = 1; |
| 117 | fadt->reset_reg.bit_width = 8; |
| 118 | fadt->reset_reg.addrl = 0xcf9; |
| 119 | fadt->reset_value = 6; |
| 120 | |
| 121 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 122 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 123 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
| 124 | |
| 125 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 126 | |
| 127 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 128 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 129 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
| 130 | |
| 131 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 132 | |
| 133 | fadt->x_pm_tmr_blk.space_id = 1; |
| 134 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 135 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 136 | |
| 137 | fadt->x_gpe1_blk.space_id = 1; |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 138 | } |
Zhao, Lijian | 30461a9 | 2015-12-01 09:14:20 -0800 | [diff] [blame] | 139 | |
| 140 | unsigned long southbridge_write_acpi_tables(device_t device, |
| 141 | unsigned long current, |
| 142 | struct acpi_rsdp *rsdp) |
| 143 | { |
| 144 | return acpi_write_hpet(device, current, rsdp); |
| 145 | } |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 146 | |
| 147 | static void acpi_create_gnvs(struct global_nvs_t *gnvs) |
| 148 | { |
Furquan Shaikh | d01f5a0 | 2016-06-13 22:23:49 -0700 | [diff] [blame] | 149 | if (IS_ENABLED(CONFIG_CONSOLE_CBMEM)) |
| 150 | gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
| 151 | |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 152 | if (IS_ENABLED(CONFIG_CHROMEOS)) { |
| 153 | /* Initialize Verified Boot data */ |
| 154 | chromeos_init_vboot(&gnvs->chromeos); |
| 155 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | void southbridge_inject_dsdt(device_t device) |
| 160 | { |
| 161 | struct global_nvs_t *gnvs; |
| 162 | |
| 163 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 164 | |
| 165 | if (gnvs) { |
| 166 | acpi_create_gnvs(gnvs); |
| 167 | acpi_save_gnvs((uintptr_t)gnvs); |
Aaron Durbin | 1ee6f0b | 2016-06-10 15:50:34 -0500 | [diff] [blame] | 168 | /* And tell SMI about it */ |
| 169 | smm_setup_structures(gnvs, NULL, NULL); |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 170 | |
| 171 | /* Add it to DSDT. */ |
| 172 | acpigen_write_scope("\\"); |
| 173 | acpigen_write_name_dword("NVSA", (uintptr_t)gnvs); |
| 174 | acpigen_pop_len(); |
| 175 | } |
| 176 | } |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 177 | static acpi_cstate_t cstate_map[] = { |
| 178 | { |
| 179 | /* C1 */ |
| 180 | .ctype = 1, /* ACPI C1 */ |
| 181 | .latency = 1, |
| 182 | .power = 1000, |
| 183 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0), |
| 184 | }, |
| 185 | { |
| 186 | .ctype = 2, /* ACPI C2 */ |
| 187 | .latency = 50, |
| 188 | .power = 10, |
| 189 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415), |
| 190 | }, |
| 191 | { |
| 192 | .ctype = 3, /* ACPI C3 */ |
| 193 | .latency = 150, |
| 194 | .power = 10, |
| 195 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419), |
| 196 | } |
| 197 | }; |
| 198 | |
| 199 | acpi_cstate_t *soc_get_cstate_map(int *entries) |
| 200 | { |
| 201 | *entries = ARRAY_SIZE(cstate_map); |
| 202 | return cstate_map; |
| 203 | } |
| 204 | |
| 205 | uint16_t soc_get_acpi_base_address(void) |
| 206 | { |
| 207 | return ACPI_PMIO_BASE; |
| 208 | } |