zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 Advanced Micro Devices, Inc. |
| 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 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * ACPI - create the Fixed ACPI Description Tables (FADT) |
| 22 | */ |
| 23 | |
| 24 | #include <string.h> |
| 25 | #include <console/console.h> |
| 26 | #include <arch/acpi.h> |
| 27 | #include <arch/io.h> |
| 28 | #include <device/device.h> |
| 29 | #include "hudson.h" |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 30 | #include "smi.h" |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 31 | |
Martin Roth | eac220f | 2013-01-16 09:07:30 -0700 | [diff] [blame] | 32 | #if CONFIG_HUDSON_LEGACY_FREE |
| 33 | #define FADT_BOOT_ARCH ACPI_FADT_LEGACY_FREE |
| 34 | #else |
| 35 | #define FADT_BOOT_ARCH (ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042) |
| 36 | #endif |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 37 | |
| 38 | #ifndef FADT_PM_PROFILE |
| 39 | #define FADT_PM_PROFILE PM_UNSPECIFIED |
| 40 | #endif |
| 41 | |
| 42 | /* |
| 43 | * Reference section 5.2.9 Fixed ACPI Description Table (FADT) |
| 44 | * in the ACPI 3.0b specification. |
| 45 | */ |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 46 | void acpi_create_fadt(acpi_fadt_t * fadt, acpi_facs_t * facs, void *dsdt) |
| 47 | { |
| 48 | acpi_header_t *header = &(fadt->header); |
| 49 | |
| 50 | printk(BIOS_DEBUG, "pm_base: 0x%04x\n", HUDSON_ACPI_IO_BASE); |
| 51 | |
| 52 | /* Prepare the header */ |
| 53 | memset((void *)fadt, 0, sizeof(acpi_fadt_t)); |
| 54 | memcpy(header->signature, "FACP", 4); |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 55 | header->length = sizeof(acpi_fadt_t); |
| 56 | header->revision = ACPI_FADT_REV_ACPI_3_0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 57 | memcpy(header->oem_id, OEM_ID, 6); |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 58 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 59 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 60 | header->asl_compiler_revision = 0; |
| 61 | |
Stefan Reinauer | fce128c | 2015-07-21 12:52:34 -0700 | [diff] [blame^] | 62 | if ((uintptr_t)facs > 0xffffffff) |
| 63 | printk(BIOS_DEBUG, "ACPI: FACS lives above 4G\n"); |
| 64 | else |
| 65 | fadt->firmware_ctrl = (uintptr_t)facs; |
| 66 | |
| 67 | if ((uintptr_t)dsdt > 0xffffffff) |
| 68 | printk(BIOS_DEBUG, "ACPI: DSDT lives above 4G\n"); |
| 69 | else |
| 70 | fadt->dsdt = (uintptr_t)dsdt; |
| 71 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 72 | fadt->model = 0; /* reserved, should be 0 ACPI 3.0 */ |
| 73 | fadt->preferred_pm_profile = FADT_PM_PROFILE; |
| 74 | fadt->sci_int = 9; /* HUDSON - IRQ 09 – ACPI SCI */ |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 75 | |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 76 | if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) { |
| 77 | fadt->smi_cmd = ACPI_SMI_CTL_PORT; |
| 78 | fadt->acpi_enable = ACPI_SMI_CMD_ENABLE; |
| 79 | fadt->acpi_disable = ACPI_SMI_CMD_DISABLE; |
| 80 | fadt->s4bios_req = 0; /* Not supported */ |
| 81 | fadt->pstate_cnt = 0; /* Not supported */ |
| 82 | fadt->cst_cnt = 0; /* Not supported */ |
Alexandru Gagniuc | 288c958 | 2014-04-14 16:35:34 -0500 | [diff] [blame] | 83 | outl(0x0, ACPI_PM1_CNT_BLK); /* clear SCI_EN */ |
| 84 | } else { |
| 85 | fadt->smi_cmd = 0; /* disable system management mode */ |
| 86 | fadt->acpi_enable = 0; /* unused if SMI_CMD = 0 */ |
| 87 | fadt->acpi_disable = 0; /* unused if SMI_CMD = 0 */ |
| 88 | fadt->s4bios_req = 0; /* unused if SMI_CMD = 0 */ |
| 89 | fadt->pstate_cnt = 0; /* unused if SMI_CMD = 0 */ |
| 90 | fadt->cst_cnt = 0x00; /* unused if SMI_CMD = 0 */ |
| 91 | outl(0x1, ACPI_PM1_CNT_BLK); /* set SCI_EN */ |
| 92 | } |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 93 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 94 | fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK; |
| 95 | fadt->pm1b_evt_blk = 0x0000; |
| 96 | fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK; |
| 97 | fadt->pm1b_cnt_blk = 0x0000; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 98 | fadt->pm2_cnt_blk = 0x0000; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 99 | fadt->pm_tmr_blk = ACPI_PM_TMR_BLK; |
| 100 | fadt->gpe0_blk = ACPI_GPE0_BLK; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 101 | fadt->gpe1_blk = 0x0000; /* No gpe1 block in hudson */ |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 102 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 103 | fadt->pm1_evt_len = 4; /* 32 bits */ |
| 104 | fadt->pm1_cnt_len = 2; /* 16 bits */ |
| 105 | fadt->pm2_cnt_len = 0; |
| 106 | fadt->pm_tmr_len = 4; /* 32 bits */ |
| 107 | fadt->gpe0_blk_len = 8; /* 64 bits */ |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 108 | fadt->gpe1_blk_len = 0; |
| 109 | fadt->gpe1_base = 0; |
| 110 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 111 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 112 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
| 113 | fadt->flush_size = 0; /* set to 0 if WBINVD is 1 in flags */ |
| 114 | fadt->flush_stride = 0; /* set to 0 if WBINVD is 1 in flags */ |
| 115 | fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */ |
| 116 | fadt->duty_width = 3; /* CLK_VAL bits 3:1 */ |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 117 | fadt->day_alrm = 0; /* 0x7d these have to be */ |
| 118 | fadt->mon_alrm = 0; /* 0x7e added to cmos.layout */ |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 119 | fadt->century = 0; /* 0x7f to make rtc alarm work */ |
| 120 | fadt->iapc_boot_arch = FADT_BOOT_ARCH; /* See table 5-10 */ |
| 121 | fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */ |
| 122 | fadt->flags = ACPI_FADT_WBINVD | /* See table 5-10 ACPI 3.0a spec */ |
| 123 | ACPI_FADT_C1_SUPPORTED | |
| 124 | ACPI_FADT_SLEEP_BUTTON | |
| 125 | ACPI_FADT_S4_RTC_WAKE | |
| 126 | ACPI_FADT_32BIT_TIMER | |
| 127 | ACPI_FADT_RESET_REGISTER | |
| 128 | ACPI_FADT_PCI_EXPRESS_WAKE | |
| 129 | ACPI_FADT_PLATFORM_CLOCK | |
| 130 | ACPI_FADT_S4_RTC_VALID | |
| 131 | ACPI_FADT_REMOTE_POWER_ON; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 132 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 133 | /* Format is from 5.2.3.1: Generic Address Structure */ |
| 134 | /* reset_reg: see section 4.7.3.6 ACPI 3.0a spec */ |
| 135 | /* 8 bit write of value 0x06 to 0xCF9 in IO space */ |
| 136 | fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 137 | fadt->reset_reg.bit_width = 8; |
| 138 | fadt->reset_reg.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 139 | fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 140 | fadt->reset_reg.addrl = 0xcf9; |
| 141 | fadt->reset_reg.addrh = 0x0; |
| 142 | |
| 143 | fadt->reset_value = 6; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 144 | |
| 145 | fadt->res3 = 0; /* reserved, MUST be 0 ACPI 3.0 */ |
| 146 | fadt->res4 = 0; /* reserved, MUST be 0 ACPI 3.0 */ |
| 147 | fadt->res5 = 0; /* reserved, MUST be 0 ACPI 3.0 */ |
| 148 | |
Stefan Reinauer | fce128c | 2015-07-21 12:52:34 -0700 | [diff] [blame^] | 149 | |
| 150 | fadt->x_firmware_ctl_l = ((uintptr_t)facs) & 0xffffffff; |
| 151 | fadt->x_firmware_ctl_h = ((uint64_t)(uintptr_t)facs) >> 32; |
| 152 | fadt->x_dsdt_l = ((uintptr_t)dsdt) & 0xffffffff; |
| 153 | fadt->x_dsdt_h = ((uint64_t)(uintptr_t)dsdt) >> 32; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 154 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 155 | fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 156 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 157 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 158 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 159 | fadt->x_pm1a_evt_blk.addrl = ACPI_PM_EVT_BLK; |
| 160 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 161 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 162 | fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 163 | fadt->x_pm1b_evt_blk.bit_width = 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 164 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 165 | fadt->x_pm1b_evt_blk.access_size = 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 166 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 167 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 168 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 169 | |
| 170 | fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 171 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 172 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 173 | fadt->x_pm1a_cnt_blk.access_size = 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 174 | fadt->x_pm1a_cnt_blk.addrl = ACPI_PM1_CNT_BLK; |
| 175 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 176 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 177 | fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 178 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 179 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 180 | fadt->x_pm1b_cnt_blk.access_size = 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 181 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 182 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 183 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 184 | /* |
| 185 | * Note: Under this current AMD C state implementation, this is no longer |
| 186 | * used and should not be reported to OS. |
| 187 | */ |
| 188 | fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 189 | fadt->x_pm2_cnt_blk.bit_width = 0; |
| 190 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 191 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 192 | fadt->x_pm2_cnt_blk.addrl = 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 193 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 194 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 195 | |
| 196 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 197 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 198 | fadt->x_pm_tmr_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 199 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 200 | fadt->x_pm_tmr_blk.addrl = ACPI_PM_TMR_BLK; |
| 201 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 202 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 203 | |
| 204 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 205 | fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */ |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 206 | fadt->x_gpe0_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 207 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 208 | fadt->x_gpe0_blk.addrl = ACPI_GPE0_BLK; |
| 209 | fadt->x_gpe0_blk.addrh = 0x0; |
| 210 | |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 211 | |
| 212 | fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 213 | fadt->x_gpe1_blk.bit_width = 0; |
| 214 | fadt->x_gpe1_blk.bit_offset = 0; |
Martin Roth | 0fbaf18 | 2013-01-10 16:40:59 -0700 | [diff] [blame] | 215 | fadt->x_gpe1_blk.access_size = 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 216 | fadt->x_gpe1_blk.addrl = 0; |
| 217 | fadt->x_gpe1_blk.addrh = 0x0; |
| 218 | |
| 219 | header->checksum = acpi_checksum((void *)fadt, sizeof(acpi_fadt_t)); |
| 220 | } |