Angel Pons | 236c637 | 2020-04-03 01:21:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 2 | |
| 3 | #include <string.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpi.h> |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 6 | #include <version.h> |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 7 | |
| 8 | /* FIXME: This needs to go into a separate .h file |
| 9 | * to be included by the ich7 smi handler, ich7 smi init |
| 10 | * code and the mainboard fadt. |
| 11 | */ |
| 12 | #define APM_CNT 0x0 /* ACPI mode only */ |
| 13 | #define CST_CONTROL 0x85 |
| 14 | #define PST_CONTROL 0x0 |
| 15 | #define ACPI_DISABLE 0xAA |
| 16 | #define ACPI_ENABLE 0x55 |
| 17 | #define S4_BIOS 0x77 |
| 18 | #define GNVS_UPDATE 0xea |
| 19 | |
| 20 | void acpi_create_fadt(acpi_fadt_t * fadt, acpi_facs_t * facs, void *dsdt) |
| 21 | { |
| 22 | acpi_header_t *header = &(fadt->header); |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 23 | u16 pmbase = pci_read_config16(pcidev_on_root(0x1f, 0), 0x40) & 0xfffe; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 24 | |
| 25 | memset((void *) fadt, 0, sizeof(acpi_fadt_t)); |
| 26 | memcpy(header->signature, "FACP", 4); |
| 27 | header->length = sizeof(acpi_fadt_t); |
Marc Jones | f9ea7ed | 2018-08-22 18:59:26 -0600 | [diff] [blame] | 28 | header->revision = get_acpi_table_revision(FADT); |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 29 | memcpy(header->oem_id, OEM_ID, 6); |
| 30 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 31 | memcpy(header->asl_compiler_id, ASLC, 4); |
Elyes HAOUAS | 26071aa | 2019-02-15 08:21:33 +0100 | [diff] [blame] | 32 | header->asl_compiler_revision = asl_revision; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 33 | |
| 34 | fadt->firmware_ctrl = (unsigned long) facs; |
| 35 | fadt->dsdt = (unsigned long) dsdt; |
Elyes HAOUAS | 0d4de2a | 2019-02-28 13:04:29 +0100 | [diff] [blame] | 36 | fadt->reserved = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 37 | fadt->preferred_pm_profile = 0; /* PM_MOBILE; */ |
| 38 | |
| 39 | fadt->sci_int = 0x9; |
Kyösti Mälkki | 06897d1 | 2019-11-23 07:23:40 +0200 | [diff] [blame^] | 40 | |
| 41 | if (CONFIG(HAVE_SMI_HANDLER)) { |
| 42 | fadt->smi_cmd = APM_CNT; |
| 43 | fadt->acpi_enable = ACPI_ENABLE; |
| 44 | fadt->acpi_disable = ACPI_DISABLE; |
| 45 | fadt->pstate_cnt = PST_CONTROL; |
| 46 | } |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 47 | |
| 48 | fadt->pm1a_evt_blk = pmbase; |
| 49 | fadt->pm1b_evt_blk = 0x0; |
| 50 | fadt->pm1a_cnt_blk = pmbase + 0x4; |
| 51 | fadt->pm1b_cnt_blk = 0x0; |
| 52 | fadt->pm2_cnt_blk = 0x0; |
| 53 | fadt->pm_tmr_blk = pmbase + 0x8; |
| 54 | fadt->gpe0_blk = pmbase + 0x28; |
| 55 | fadt->gpe1_blk = 0; |
| 56 | |
| 57 | fadt->pm1_evt_len = 4; |
| 58 | fadt->pm1_cnt_len = 2; |
Elyes HAOUAS | 4682986 | 2016-10-07 17:35:50 +0200 | [diff] [blame] | 59 | /* XXX: pm2_cnt_len is probably wrong. find out right value (hint: it's != 0) */ |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 60 | fadt->pm2_cnt_len = 0; |
| 61 | fadt->pm_tmr_len = 4; |
| 62 | fadt->gpe0_blk_len = 8; |
| 63 | fadt->gpe1_blk_len = 0; |
| 64 | fadt->gpe1_base = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 65 | fadt->p_lvl2_lat = 1; |
| 66 | fadt->p_lvl3_lat = 85; |
| 67 | fadt->flush_size = 1024; |
| 68 | fadt->flush_stride = 16; |
| 69 | fadt->duty_offset = 1; |
| 70 | fadt->duty_width = 0; |
| 71 | fadt->day_alrm = 0xd; |
| 72 | fadt->mon_alrm = 0x00; |
| 73 | fadt->century = 0x00; |
| 74 | fadt->iapc_boot_arch = 0x03; |
| 75 | |
| 76 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 77 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 78 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 79 | |
| 80 | fadt->reset_reg.space_id = 0; |
| 81 | fadt->reset_reg.bit_width = 0; |
| 82 | fadt->reset_reg.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 83 | fadt->reset_reg.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 84 | fadt->reset_reg.addrl = 0x0; |
| 85 | fadt->reset_reg.addrh = 0x0; |
| 86 | |
| 87 | fadt->reset_value = 0; |
| 88 | fadt->x_firmware_ctl_l = (unsigned long)facs; |
| 89 | fadt->x_firmware_ctl_h = 0; |
| 90 | fadt->x_dsdt_l = (unsigned long)dsdt; |
| 91 | fadt->x_dsdt_h = 0; |
| 92 | |
| 93 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 94 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 95 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 96 | fadt->x_pm1a_evt_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 97 | fadt->x_pm1a_evt_blk.addrl = pmbase; |
| 98 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 99 | |
| 100 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 101 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 102 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 103 | fadt->x_pm1b_evt_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 104 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 105 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 106 | |
| 107 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 108 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 109 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 110 | fadt->x_pm1a_cnt_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 111 | fadt->x_pm1a_cnt_blk.addrl = pmbase + 0x4; |
| 112 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 113 | |
| 114 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 115 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 116 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 117 | fadt->x_pm1b_cnt_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 118 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 119 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 120 | |
| 121 | fadt->x_pm2_cnt_blk.space_id = 1; |
| 122 | fadt->x_pm2_cnt_blk.bit_width = 0; |
| 123 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 124 | fadt->x_pm2_cnt_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 125 | fadt->x_pm2_cnt_blk.addrl = 0x0; |
| 126 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 127 | |
| 128 | fadt->x_pm_tmr_blk.space_id = 1; |
| 129 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 130 | fadt->x_pm_tmr_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 131 | fadt->x_pm_tmr_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 132 | fadt->x_pm_tmr_blk.addrl = pmbase + 0x8; |
| 133 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 134 | |
| 135 | fadt->x_gpe0_blk.space_id = 1; |
| 136 | fadt->x_gpe0_blk.bit_width = 64; |
| 137 | fadt->x_gpe0_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 138 | fadt->x_gpe0_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 139 | fadt->x_gpe0_blk.addrl = pmbase + 0x28; |
| 140 | fadt->x_gpe0_blk.addrh = 0x0; |
| 141 | |
| 142 | fadt->x_gpe1_blk.space_id = 1; |
| 143 | fadt->x_gpe1_blk.bit_width = 0; |
| 144 | fadt->x_gpe1_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 145 | fadt->x_gpe1_blk.access_size = 0; |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 146 | fadt->x_gpe1_blk.addrl = 0x0; |
| 147 | fadt->x_gpe1_blk.addrh = 0x0; |
| 148 | |
Jonathan Neuschäfer | e1de648 | 2018-10-10 14:22:48 +0200 | [diff] [blame] | 149 | header->checksum = acpi_checksum((void *) fadt, header->length); |
Kyösti Mälkki | 9116270 | 2011-11-03 15:22:01 +0200 | [diff] [blame] | 150 | } |