blob: 5823813011722e0858903192dcd87720b1d519ff [file] [log] [blame]
Frank Vibrans69da1b62011-02-14 19:04:45 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 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.
Frank Vibrans69da1b62011-02-14 19:04:45 +000014 */
15
16
17/*
18 * ACPI - create the Fixed ACPI Description Tables (FADT)
19 */
20
21
22#include <string.h>
23#include <console/console.h>
24#include <arch/acpi.h>
25#include <arch/io.h>
26#include <device/device.h>
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010027#include <version.h>
28
Kerry Shefeed3292011-08-18 18:03:44 +080029#include "SBPLATFORM.h"
Frank Vibrans69da1b62011-02-14 19:04:45 +000030
Marc Jones7c9ef4f2012-05-10 11:02:32 -060031#ifndef FADT_BOOT_ARCH
32#if LEGACY_FREE
Marc Jones7c9ef4f2012-05-10 11:02:32 -060033 #define FADT_BOOT_ARCH ACPI_FADT_LEGACY_FREE
Marc Jonesba3711c2012-05-12 09:56:45 -060034#else
35 #define FADT_BOOT_ARCH (ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042)
Marc Jones7c9ef4f2012-05-10 11:02:32 -060036#endif
37#endif
Marc Jonesb547c4f2012-05-09 15:34:49 -060038
Martin Roth9aa43892012-05-25 12:23:32 -060039#ifndef FADT_PM_PROFILE
40 #define FADT_PM_PROFILE PM_UNSPECIFIED
41#endif
42
Marc Jonesb547c4f2012-05-09 15:34:49 -060043/*
44 * Reference section 5.2.9 Fixed ACPI Description Table (FADT)
45 * in the ACPI 3.0b specification.
46 */
Frank Vibrans69da1b62011-02-14 19:04:45 +000047void acpi_create_fadt(acpi_fadt_t * fadt, acpi_facs_t * facs, void *dsdt)
48{
Kerry Shefeed3292011-08-18 18:03:44 +080049 u16 val = 0;
Frank Vibrans69da1b62011-02-14 19:04:45 +000050 acpi_header_t *header = &(fadt->header);
51
Kerry Shefeed3292011-08-18 18:03:44 +080052 printk(BIOS_DEBUG, "ACPI_BLK_BASE: 0x%04x\n", ACPI_BLK_BASE);
Marc Jonesb547c4f2012-05-09 15:34:49 -060053
Frank Vibrans69da1b62011-02-14 19:04:45 +000054 /* Prepare the header */
55 memset((void *)fadt, 0, sizeof(acpi_fadt_t));
56 memcpy(header->signature, "FACP", 4);
Marc Jonesb547c4f2012-05-09 15:34:49 -060057 header->length = sizeof(acpi_fadt_t);
Marc Jonesf9ea7ed2018-08-22 18:59:26 -060058 header->revision = get_acpi_table_revision(FADT);
Frank Vibrans69da1b62011-02-14 19:04:45 +000059 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauerfa66eae2012-09-06 12:13:43 -070060 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Frank Vibrans69da1b62011-02-14 19:04:45 +000061 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010062 header->asl_compiler_revision = asl_revision;
Frank Vibrans69da1b62011-02-14 19:04:45 +000063
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070064 if ((uintptr_t)facs > 0xffffffff)
65 printk(BIOS_DEBUG, "ACPI: FACS lives above 4G\n");
66 else
67 fadt->firmware_ctrl = (uintptr_t)facs;
68
69 if ((uintptr_t)dsdt > 0xffffffff)
70 printk(BIOS_DEBUG, "ACPI: DSDT lives above 4G\n");
71 else
72 fadt->dsdt = (uintptr_t)dsdt;
73
Marc Jonesb547c4f2012-05-09 15:34:49 -060074 fadt->model = 0; /* reserved, should be 0 ACPI 3.0 */
Martin Roth9aa43892012-05-25 12:23:32 -060075 fadt->preferred_pm_profile = FADT_PM_PROFILE;
Martin Roth0cd338e2016-07-29 14:07:30 -060076 fadt->sci_int = 9; /* HUDSON 1 - IRQ 09 - ACPI SCI */
Marc Jonesb547c4f2012-05-09 15:34:49 -060077 fadt->smi_cmd = 0; /* disable system management mode */
78 fadt->acpi_enable = 0; /* unused if SMI_CMD = 0 */
79 fadt->acpi_disable = 0; /* unused if SMI_CMD = 0 */
80 fadt->s4bios_req = 0; /* unused if SMI_CMD = 0 */
81 fadt->pstate_cnt = 0; /* unused if SMI_CMD = 0 */
Frank Vibrans69da1b62011-02-14 19:04:45 +000082
Kerry Shefeed3292011-08-18 18:03:44 +080083 val = PM1_EVT_BLK_ADDRESS;
84 WritePMIO(SB_PMIOA_REG60, AccWidthUint16, &val);
85 val = PM1_CNT_BLK_ADDRESS;
86 WritePMIO(SB_PMIOA_REG62, AccWidthUint16, &val);
87 val = PM1_TMR_BLK_ADDRESS;
88 WritePMIO(SB_PMIOA_REG64, AccWidthUint16, &val);
89 val = GPE0_BLK_ADDRESS;
90 WritePMIO(SB_PMIOA_REG68, AccWidthUint16, &val);
Frank Vibrans69da1b62011-02-14 19:04:45 +000091
Timothy Pearson033bb4b2015-02-10 22:21:39 -060092 /* CpuControl is in \_PR.CP00, 6 bytes */
Kerry Shefeed3292011-08-18 18:03:44 +080093 val = CPU_CNT_BLK_ADDRESS;
94 WritePMIO(SB_PMIOA_REG66, AccWidthUint16, &val);
95 val = 0;
96 WritePMIO(SB_PMIOA_REG6A, AccWidthUint16, &val);
97 val = ACPI_PMA_CNT_BLK_ADDRESS;
Martin Roth9aa43892012-05-25 12:23:32 -060098 WritePMIO(SB_PMIOA_REG6E, AccWidthUint16, &val);
Frank Vibrans69da1b62011-02-14 19:04:45 +000099
Kerry Shefeed3292011-08-18 18:03:44 +0800100 /* AcpiDecodeEnable, When set, SB uses the contents of the
101 * PM registers at index 60-6B to decode ACPI I/O address.
102 * AcpiSmiEn & SmiCmdEn*/
103 val = BIT0 | BIT1 | BIT2 | BIT4;
104 WritePMIO(SB_PMIOA_REG74, AccWidthUint16, &val);
Frank Vibrans69da1b62011-02-14 19:04:45 +0000105
Frank Vibrans69da1b62011-02-14 19:04:45 +0000106 /* RTC_En_En, TMR_En_En, GBL_EN_EN */
Kerry Shefeed3292011-08-18 18:03:44 +0800107 outl(0x1, PM1_CNT_BLK_ADDRESS); /* set SCI_EN */
108 fadt->pm1a_evt_blk = PM1_EVT_BLK_ADDRESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000109 fadt->pm1b_evt_blk = 0x0000;
Kerry Shefeed3292011-08-18 18:03:44 +0800110 fadt->pm1a_cnt_blk = PM1_CNT_BLK_ADDRESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000111 fadt->pm1b_cnt_blk = 0x0000;
Kerry Shefeed3292011-08-18 18:03:44 +0800112 fadt->pm2_cnt_blk = ACPI_PMA_CNT_BLK_ADDRESS;
113 fadt->pm_tmr_blk = PM1_TMR_BLK_ADDRESS;
114 fadt->gpe0_blk = GPE0_BLK_ADDRESS;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600115 fadt->gpe1_blk = 0; /* No gpe1 block in hudson1 */
Frank Vibrans69da1b62011-02-14 19:04:45 +0000116
Martin Roth9aa43892012-05-25 12:23:32 -0600117 fadt->pm1_evt_len = 4; /* 32 bits */
118 fadt->pm1_cnt_len = 2; /* 16 bits */
119 fadt->pm2_cnt_len = 1; /* 8 bits */
120 fadt->pm_tmr_len = 4; /* 32 bits */
121 fadt->gpe0_blk_len = 8; /* 64 bits */
Frank Vibrans69da1b62011-02-14 19:04:45 +0000122 fadt->gpe1_blk_len = 0;
123 fadt->gpe1_base = 0;
124
Martin Roth9aa43892012-05-25 12:23:32 -0600125 fadt->cst_cnt = 0x00; /* unused if SMI_CMD = 0 */
126 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
127 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600128 fadt->flush_size = 0; /* set to 0 if WBINVD is 1 in flags */
129 fadt->flush_stride = 0; /* set to 0 if WBINVD is 1 in flags */
Martin Roth9aa43892012-05-25 12:23:32 -0600130 fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */
131 fadt->duty_width = 3; /* CLK_VAL bits 3:1 */
Frank Vibrans69da1b62011-02-14 19:04:45 +0000132 fadt->day_alrm = 0; /* 0x7d these have to be */
133 fadt->mon_alrm = 0; /* 0x7e added to cmos.layout */
Martin Roth3c3a50c2014-12-16 20:50:26 -0700134 fadt->century = 0; /* 0x7f to make rtc alarm work */
Marc Jones7c9ef4f2012-05-10 11:02:32 -0600135 fadt->iapc_boot_arch = FADT_BOOT_ARCH; /* See table 5-10 */
Marc Jonesb547c4f2012-05-09 15:34:49 -0600136 fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */
137 fadt->flags = ACPI_FADT_WBINVD | /* See table 5-10 ACPI 3.0a spec */
138 ACPI_FADT_C1_SUPPORTED |
139 ACPI_FADT_SLEEP_BUTTON |
140 ACPI_FADT_S4_RTC_WAKE |
141 ACPI_FADT_32BIT_TIMER |
142 ACPI_FADT_RESET_REGISTER |
143 ACPI_FADT_PCI_EXPRESS_WAKE |
144 ACPI_FADT_S4_RTC_VALID |
145 ACPI_FADT_REMOTE_POWER_ON;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000146
Marc Jonesb547c4f2012-05-09 15:34:49 -0600147 /* Format is from 5.2.3.1: Generic Address Structure */
148 /* reset_reg: see section 4.7.3.6 ACPI 3.0a spec */
149 /* 8 bit write of value 0x06 to 0xCF9 in IO space */
150 fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000151 fadt->reset_reg.bit_width = 8;
152 fadt->reset_reg.bit_offset = 0;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600153 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000154 fadt->reset_reg.addrl = 0xcf9;
155 fadt->reset_reg.addrh = 0x0;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000156 fadt->reset_value = 6;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600157
Elyes HAOUASf5b974e2018-11-10 20:29:08 +0100158 fadt->ARM_boot_arch = 0; /* MUST be 0 ACPI 3.0 */
159 fadt->FADT_MinorVersion = 0; /* MUST be 0 ACPI 3.0 */
Marc Jonesb547c4f2012-05-09 15:34:49 -0600160
Stefan Reinauer12bce3f2015-06-18 01:17:38 -0700161 fadt->x_firmware_ctl_l = ((uintptr_t)facs) & 0xffffffff;
162 fadt->x_firmware_ctl_h = ((uint64_t)(uintptr_t)facs) >> 32;
163 fadt->x_dsdt_l = ((uintptr_t)dsdt) & 0xffffffff;
164 fadt->x_dsdt_h = ((uint64_t)(uintptr_t)dsdt) >> 32;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000165
Marc Jonesb547c4f2012-05-09 15:34:49 -0600166 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000167 fadt->x_pm1a_evt_blk.bit_width = 32;
168 fadt->x_pm1a_evt_blk.bit_offset = 0;
Martin Roth9aa43892012-05-25 12:23:32 -0600169 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Kerry Shefeed3292011-08-18 18:03:44 +0800170 fadt->x_pm1a_evt_blk.addrl = PM1_EVT_BLK_ADDRESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000171 fadt->x_pm1a_evt_blk.addrh = 0x0;
172
Marc Jonesb547c4f2012-05-09 15:34:49 -0600173 fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
174 fadt->x_pm1b_evt_blk.bit_width = 0;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000175 fadt->x_pm1b_evt_blk.bit_offset = 0;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600176 fadt->x_pm1b_evt_blk.access_size = 0;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000177 fadt->x_pm1b_evt_blk.addrl = 0x0;
178 fadt->x_pm1b_evt_blk.addrh = 0x0;
179
180
Marc Jonesb547c4f2012-05-09 15:34:49 -0600181 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000182 fadt->x_pm1a_cnt_blk.bit_width = 16;
183 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600184 fadt->x_pm1a_cnt_blk.access_size = 0;
Kerry Shefeed3292011-08-18 18:03:44 +0800185 fadt->x_pm1a_cnt_blk.addrl = PM1_CNT_BLK_ADDRESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000186 fadt->x_pm1a_cnt_blk.addrh = 0x0;
187
Marc Jonesb547c4f2012-05-09 15:34:49 -0600188 fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
189 fadt->x_pm1b_cnt_blk.bit_width = 0;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000190 fadt->x_pm1b_cnt_blk.bit_offset = 0;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600191 fadt->x_pm1b_cnt_blk.access_size = 0;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000192 fadt->x_pm1b_cnt_blk.addrl = 0x0;
193 fadt->x_pm1b_cnt_blk.addrh = 0x0;
194
195
Marc Jonesb547c4f2012-05-09 15:34:49 -0600196 fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
197 fadt->x_pm2_cnt_blk.bit_width = 8; /* Hudson 1 Pm2Control is 8 bits */
Frank Vibrans69da1b62011-02-14 19:04:45 +0000198 fadt->x_pm2_cnt_blk.bit_offset = 0;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600199 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Kerry Shefeed3292011-08-18 18:03:44 +0800200 fadt->x_pm2_cnt_blk.addrl = ACPI_PMA_CNT_BLK_ADDRESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000201 fadt->x_pm2_cnt_blk.addrh = 0x0;
202
203
Marc Jonesb547c4f2012-05-09 15:34:49 -0600204 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000205 fadt->x_pm_tmr_blk.bit_width = 32;
206 fadt->x_pm_tmr_blk.bit_offset = 0;
Martin Roth9aa43892012-05-25 12:23:32 -0600207 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Kerry Shefeed3292011-08-18 18:03:44 +0800208 fadt->x_pm_tmr_blk.addrl = PM1_TMR_BLK_ADDRESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000209 fadt->x_pm_tmr_blk.addrh = 0x0;
210
211
Marc Jonesb547c4f2012-05-09 15:34:49 -0600212 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Martin Roth9aa43892012-05-25 12:23:32 -0600213 fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */
Frank Vibrans69da1b62011-02-14 19:04:45 +0000214 fadt->x_gpe0_blk.bit_offset = 0;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600215 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Kerry Shefeed3292011-08-18 18:03:44 +0800216 fadt->x_gpe0_blk.addrl = GPE0_BLK_ADDRESS;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000217 fadt->x_gpe0_blk.addrh = 0x0;
218
219
Marc Jonesb547c4f2012-05-09 15:34:49 -0600220 fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000221 fadt->x_gpe1_blk.bit_width = 0;
222 fadt->x_gpe1_blk.bit_offset = 0;
Marc Jonesb547c4f2012-05-09 15:34:49 -0600223 fadt->x_gpe1_blk.access_size = 0;
Frank Vibrans69da1b62011-02-14 19:04:45 +0000224 fadt->x_gpe1_blk.addrl = 0;
225 fadt->x_gpe1_blk.addrh = 0x0;
226
227 header->checksum = acpi_checksum((void *)fadt, sizeof(acpi_fadt_t));
228
229}