Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 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. |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <string.h> |
| 17 | #include <device/pci.h> |
| 18 | #include <arch/acpi.h> |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 19 | #include <cpu/x86/smm.h> |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 20 | |
| 21 | void acpi_create_fadt(acpi_fadt_t * fadt, acpi_facs_t * facs, void *dsdt) |
| 22 | { |
| 23 | acpi_header_t *header = &(fadt->header); |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 24 | u16 pmbase = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0x1f, 0)), |
| 25 | 0x40) & 0xfffe; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 26 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 27 | memset((void *)fadt, 0, sizeof(acpi_fadt_t)); |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 28 | memcpy(header->signature, "FACP", 4); |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 29 | header->length = sizeof(acpi_fadt_t); |
| 30 | header->revision = 3; |
Stefan Reinauer | 03f82bd | 2011-09-20 22:36:32 +0200 | [diff] [blame] | 31 | memcpy(header->oem_id, OEM_ID, 6); |
| 32 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 33 | memcpy(header->asl_compiler_id, ASLC, 4); |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 34 | header->asl_compiler_revision = 1; |
| 35 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 36 | fadt->firmware_ctrl = (unsigned long)facs; |
| 37 | fadt->dsdt = (unsigned long)dsdt; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 38 | fadt->model = 1; |
| 39 | fadt->preferred_pm_profile = PM_MOBILE; |
| 40 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 41 | fadt->sci_int = 0x9; |
| 42 | fadt->smi_cmd = APM_CNT; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 43 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 44 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 45 | fadt->s4bios_req = 0x0; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 46 | fadt->pstate_cnt = APM_CNT_PST_CONTROL; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [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 = pmbase + 0x20; |
| 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; |
| 59 | // XXX: pm2_cnt_len is probably wrong. find out right value (hint: it's != 0) |
| 60 | fadt->pm2_cnt_len = 2; |
| 61 | fadt->pm_tmr_len = 4; |
| 62 | fadt->gpe0_blk_len = 8; |
| 63 | fadt->gpe1_blk_len = 0; |
| 64 | fadt->gpe1_base = 0; |
Sven Schnelle | f4dc1a7 | 2011-06-05 11:33:41 +0200 | [diff] [blame] | 65 | fadt->cst_cnt = APM_CNT_CST_CONTROL; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 66 | fadt->p_lvl2_lat = 1; |
| 67 | fadt->p_lvl3_lat = 85; |
| 68 | fadt->flush_size = 1024; |
| 69 | fadt->flush_stride = 16; |
| 70 | fadt->duty_offset = 1; |
| 71 | fadt->duty_width = 0; |
| 72 | fadt->day_alrm = 0xd; |
| 73 | fadt->mon_alrm = 0x00; |
| 74 | fadt->century = 0x00; |
| 75 | fadt->iapc_boot_arch = 0x03; |
| 76 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 77 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 78 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 79 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 80 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 81 | fadt->reset_reg.space_id = 0; |
| 82 | fadt->reset_reg.bit_width = 0; |
| 83 | fadt->reset_reg.bit_offset = 0; |
| 84 | fadt->reset_reg.resv = 0; |
| 85 | fadt->reset_reg.addrl = 0x0; |
| 86 | fadt->reset_reg.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 87 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 88 | fadt->reset_value = 0; |
| 89 | fadt->x_firmware_ctl_l = (unsigned long)facs; |
| 90 | fadt->x_firmware_ctl_h = 0; |
| 91 | fadt->x_dsdt_l = (unsigned long)dsdt; |
| 92 | fadt->x_dsdt_h = 0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 93 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 94 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 95 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 96 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
| 97 | fadt->x_pm1a_evt_blk.resv = 0; |
| 98 | fadt->x_pm1a_evt_blk.addrl = pmbase; |
| 99 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 100 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 101 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 102 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 103 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
| 104 | fadt->x_pm1b_evt_blk.resv = 0; |
| 105 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 106 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 107 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 108 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 109 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 110 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
| 111 | fadt->x_pm1a_cnt_blk.resv = 0; |
| 112 | fadt->x_pm1a_cnt_blk.addrl = pmbase + 0x4; |
| 113 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 114 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 115 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 116 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 117 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
| 118 | fadt->x_pm1b_cnt_blk.resv = 0; |
| 119 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 120 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 121 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 122 | fadt->x_pm2_cnt_blk.space_id = 1; |
| 123 | fadt->x_pm2_cnt_blk.bit_width = 8; |
| 124 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 125 | fadt->x_pm2_cnt_blk.resv = 0; |
| 126 | fadt->x_pm2_cnt_blk.addrl = pmbase + 0x20; |
| 127 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 128 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 129 | fadt->x_pm_tmr_blk.space_id = 1; |
| 130 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 131 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 132 | fadt->x_pm_tmr_blk.resv = 0; |
| 133 | fadt->x_pm_tmr_blk.addrl = pmbase + 0x8; |
| 134 | fadt->x_pm_tmr_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 135 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 136 | fadt->x_gpe0_blk.space_id = 1; |
| 137 | fadt->x_gpe0_blk.bit_width = 64; |
| 138 | fadt->x_gpe0_blk.bit_offset = 0; |
| 139 | fadt->x_gpe0_blk.resv = 0; |
| 140 | fadt->x_gpe0_blk.addrl = pmbase + 0x28; |
| 141 | fadt->x_gpe0_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 142 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 143 | fadt->x_gpe1_blk.space_id = 1; |
| 144 | fadt->x_gpe1_blk.bit_width = 0; |
| 145 | fadt->x_gpe1_blk.bit_offset = 0; |
| 146 | fadt->x_gpe1_blk.resv = 0; |
| 147 | fadt->x_gpe1_blk.addrl = 0x0; |
| 148 | fadt->x_gpe1_blk.addrh = 0x0; |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 149 | |
Uwe Hermann | 405721d | 2010-12-18 13:22:37 +0000 | [diff] [blame] | 150 | header->checksum = acpi_checksum((void *)fadt, header->length); |
Patrick Georgi | be61a17 | 2010-12-18 07:48:43 +0000 | [diff] [blame] | 151 | } |