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> |
| 24 | #include <soc/acpi.h> |
| 25 | #include <soc/iomap.h> |
| 26 | #include <soc/pm.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 27 | #include <soc/nvs.h> |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 28 | |
| 29 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 30 | { |
Lance Zhao | 2c34e31 | 2015-11-16 18:13:23 -0800 | [diff] [blame] | 31 | /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */ |
| 32 | current += acpi_create_mcfg_mmconfig((void *) current, |
| 33 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, |
| 34 | 255); |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 35 | return current; |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 36 | } |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 37 | |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 38 | static int acpi_sci_irq(void) |
| 39 | { |
| 40 | int sci_irq = 9; |
| 41 | return sci_irq; |
| 42 | } |
| 43 | |
Lance Zhao | 2fc82d6 | 2015-11-16 18:33:21 -0800 | [diff] [blame] | 44 | static unsigned long acpi_madt_irq_overrides(unsigned long current) |
| 45 | { |
| 46 | int sci = acpi_sci_irq(); |
| 47 | uint16_t flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW;; |
| 48 | |
| 49 | /* INT_SRC_OVR */ |
| 50 | current += acpi_create_madt_irqoverride((void *)current, 0, 0, 2, 0); |
| 51 | |
| 52 | /* SCI */ |
| 53 | current += acpi_create_madt_irqoverride((void *)current, 0, sci, sci, flags); |
| 54 | |
| 55 | return current; |
| 56 | } |
| 57 | |
| 58 | unsigned long acpi_fill_madt(unsigned long current) |
| 59 | { |
| 60 | /* Local APICs */ |
| 61 | current = acpi_create_madt_lapics(current); |
| 62 | |
| 63 | /* IOAPIC */ |
| 64 | current += acpi_create_madt_ioapic((void *) current, |
| 65 | 2, IO_APIC_ADDR, 0); |
| 66 | |
| 67 | return acpi_madt_irq_overrides(current); |
| 68 | } |
| 69 | |
Aaron Durbin | c3ee3f6 | 2016-05-11 10:35:49 -0500 | [diff] [blame] | 70 | void acpi_fill_fadt(acpi_fadt_t * fadt) |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 71 | { |
| 72 | const uint16_t pmbase = ACPI_PMIO_BASE; |
| 73 | |
Aaron Durbin | c3ee3f6 | 2016-05-11 10:35:49 -0500 | [diff] [blame] | 74 | /* Use ACPI 5.0 revision. */ |
| 75 | fadt->header.revision = ACPI_FADT_REV_ACPI_5_0; |
| 76 | |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 77 | fadt->sci_int = acpi_sci_irq(); |
| 78 | fadt->smi_cmd = 0; /* No Smi Handler as SMI_CMD is 0*/ |
| 79 | |
| 80 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
| 81 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
| 82 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 83 | fadt->gpe0_blk = pmbase + GPE0_STS(0); |
| 84 | |
| 85 | fadt->pm1_evt_len = 4; |
| 86 | fadt->pm1_cnt_len = 2; |
| 87 | fadt->pm_tmr_len = 4; |
| 88 | /* There are 4 GPE0 STS/EN pairs each 32 bits wide. */ |
| 89 | fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t); |
| 90 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 91 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 92 | fadt->flush_size = 0x400; /* twice of cache size*/ |
| 93 | fadt->flush_stride = 0x10; /* Cache line width */ |
| 94 | fadt->duty_offset = 1; |
| 95 | fadt->duty_width = 3; |
| 96 | fadt->day_alrm = 0xd; |
| 97 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 98 | |
| 99 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 100 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 101 | ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE | |
| 102 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 103 | |
| 104 | fadt->reset_reg.space_id = 1; |
| 105 | fadt->reset_reg.bit_width = 8; |
| 106 | fadt->reset_reg.addrl = 0xcf9; |
| 107 | fadt->reset_value = 6; |
| 108 | |
| 109 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 110 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 111 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
| 112 | |
| 113 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 114 | |
| 115 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 116 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 117 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
| 118 | |
| 119 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 120 | |
| 121 | fadt->x_pm_tmr_blk.space_id = 1; |
| 122 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 123 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 124 | |
| 125 | fadt->x_gpe1_blk.space_id = 1; |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 126 | } |
Zhao, Lijian | 30461a9 | 2015-12-01 09:14:20 -0800 | [diff] [blame] | 127 | |
| 128 | unsigned long southbridge_write_acpi_tables(device_t device, |
| 129 | unsigned long current, |
| 130 | struct acpi_rsdp *rsdp) |
| 131 | { |
| 132 | return acpi_write_hpet(device, current, rsdp); |
| 133 | } |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 134 | |
| 135 | static void acpi_create_gnvs(struct global_nvs_t *gnvs) |
| 136 | { |
| 137 | if (IS_ENABLED(CONFIG_CHROMEOS)) { |
| 138 | /* Initialize Verified Boot data */ |
| 139 | chromeos_init_vboot(&gnvs->chromeos); |
| 140 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void southbridge_inject_dsdt(device_t device) |
| 145 | { |
| 146 | struct global_nvs_t *gnvs; |
| 147 | |
| 148 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 149 | |
| 150 | if (gnvs) { |
| 151 | acpi_create_gnvs(gnvs); |
| 152 | acpi_save_gnvs((uintptr_t)gnvs); |
| 153 | |
| 154 | /* Add it to DSDT. */ |
| 155 | acpigen_write_scope("\\"); |
| 156 | acpigen_write_name_dword("NVSA", (uintptr_t)gnvs); |
| 157 | acpigen_pop_len(); |
| 158 | } |
| 159 | } |