Saket Sinha | e94019e | 2015-08-22 12:20:56 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/acpi_table.h> |
| 9 | #include <asm/ioapic.h> |
| 10 | #include <asm/tables.h> |
| 11 | |
| 12 | void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs, |
| 13 | void *dsdt) |
| 14 | { |
| 15 | acpi_header_t *header = &(fadt->header); |
| 16 | u16 pmbase; |
| 17 | |
| 18 | pci_dev_t bdf = PCI_BDF(0, 0x1f, 0); |
| 19 | pci_read_config_word(bdf, 0x40, &pmbase); |
| 20 | |
| 21 | /* |
| 22 | * TODO(saket.sinha89@gmail.com): wrong value |
| 23 | * of pmbase by above function. Hard-coding it to |
| 24 | * correct value. Since no PCI register is |
| 25 | * programmed Power Management Interface is |
| 26 | * not working |
| 27 | */ |
| 28 | pmbase = 0x0600; |
| 29 | |
| 30 | memset((void *)fadt, 0, sizeof(struct acpi_fadt)); |
| 31 | memcpy(header->signature, "FACP", 4); |
| 32 | header->length = sizeof(struct acpi_fadt); |
| 33 | header->revision = 3; |
| 34 | memcpy(header->oem_id, OEM_ID, 6); |
| 35 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 36 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 37 | header->asl_compiler_revision = 0; |
| 38 | |
| 39 | fadt->firmware_ctrl = (unsigned long) facs; |
| 40 | fadt->dsdt = (unsigned long) dsdt; |
| 41 | fadt->model = 0x00; |
| 42 | fadt->preferred_pm_profile = PM_MOBILE; |
| 43 | fadt->sci_int = 0x9; |
| 44 | fadt->smi_cmd = 0; |
| 45 | fadt->acpi_enable = 0; |
| 46 | fadt->acpi_disable = 0; |
| 47 | fadt->s4bios_req = 0x0; |
| 48 | fadt->pstate_cnt = 0; |
| 49 | fadt->pm1a_evt_blk = pmbase; |
| 50 | fadt->pm1b_evt_blk = 0x0; |
| 51 | fadt->pm1a_cnt_blk = pmbase + 0x4; |
| 52 | fadt->pm1b_cnt_blk = 0x0; |
| 53 | fadt->pm2_cnt_blk = pmbase + 0x50; |
| 54 | fadt->pm_tmr_blk = pmbase + 0x8; |
| 55 | fadt->gpe0_blk = pmbase + 0x20; |
| 56 | fadt->gpe1_blk = 0; |
| 57 | fadt->pm1_evt_len = 4; |
| 58 | /* |
| 59 | * Upper word is reserved and |
| 60 | * Linux complains about 32 bit |
| 61 | */ |
| 62 | fadt->pm1_cnt_len = 2; |
| 63 | fadt->pm2_cnt_len = 1; |
| 64 | fadt->pm_tmr_len = 4; |
| 65 | fadt->gpe0_blk_len = 16; |
| 66 | fadt->gpe1_blk_len = 0; |
| 67 | fadt->gpe1_base = 0; |
| 68 | fadt->cst_cnt = 0; |
| 69 | fadt->p_lvl2_lat = 1; |
| 70 | fadt->p_lvl3_lat = 0x39; |
| 71 | fadt->flush_size = 0; |
| 72 | fadt->flush_stride = 0; |
| 73 | fadt->duty_offset = 1; |
| 74 | fadt->duty_width = 3; |
| 75 | fadt->day_alrm = 0xd; |
| 76 | fadt->mon_alrm = 0x00; |
| 77 | fadt->century = 0x32; |
| 78 | fadt->iapc_boot_arch = 0x00; |
| 79 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 80 | ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_S4_RTC_WAKE | |
| 81 | ACPI_FADT_DOCKING_SUPPORTED | ACPI_FADT_RESET_REGISTER | |
| 82 | ACPI_FADT_PLATFORM_CLOCK; |
| 83 | fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO; |
| 84 | fadt->reset_reg.bit_width = 8; |
| 85 | fadt->reset_reg.bit_offset = 0; |
| 86 | fadt->reset_reg.resv = 0; |
| 87 | fadt->reset_reg.addrl = 0xcf9; |
| 88 | fadt->reset_reg.addrh = 0; |
| 89 | fadt->reset_value = 0x06; |
| 90 | /* |
| 91 | * Set X_FIRMWARE_CTRL only if FACS is |
| 92 | * above 4GB. If X_FIRMWARE_CTRL is set, |
| 93 | * then FIRMWARE_CTRL must be zero |
| 94 | */ |
| 95 | fadt->x_firmware_ctl_l = 0; |
| 96 | fadt->x_firmware_ctl_h = 0; |
| 97 | fadt->x_dsdt_l = (unsigned long)dsdt; |
| 98 | fadt->x_dsdt_h = 0; |
| 99 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 100 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 101 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
| 102 | fadt->x_pm1a_evt_blk.resv = 0; |
| 103 | fadt->x_pm1a_evt_blk.addrl = pmbase; |
| 104 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 105 | fadt->x_pm1b_evt_blk.space_id = 0; |
| 106 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 107 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
| 108 | fadt->x_pm1b_evt_blk.resv = 0; |
| 109 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 110 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 111 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 112 | /* |
| 113 | * Upper word is reserved and |
| 114 | * Linux complains about 32 bit |
| 115 | */ |
| 116 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 117 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
| 118 | fadt->x_pm1a_cnt_blk.resv = 0; |
| 119 | fadt->x_pm1a_cnt_blk.addrl = pmbase + 0x4; |
| 120 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 121 | fadt->x_pm1b_cnt_blk.space_id = 0; |
| 122 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 123 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
| 124 | fadt->x_pm1b_cnt_blk.resv = 0; |
| 125 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 126 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 127 | fadt->x_pm2_cnt_blk.space_id = 1; |
| 128 | fadt->x_pm2_cnt_blk.bit_width = 8; |
| 129 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 130 | fadt->x_pm2_cnt_blk.resv = 0; |
| 131 | fadt->x_pm2_cnt_blk.addrl = pmbase + 0x50; |
| 132 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 133 | fadt->x_pm_tmr_blk.space_id = 1; |
| 134 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 135 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 136 | fadt->x_pm_tmr_blk.resv = 0; |
| 137 | fadt->x_pm_tmr_blk.addrl = pmbase + 0x8; |
| 138 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 139 | fadt->x_gpe0_blk.space_id = 1; |
| 140 | fadt->x_gpe0_blk.bit_width = 128; |
| 141 | fadt->x_gpe0_blk.bit_offset = 0; |
| 142 | fadt->x_gpe0_blk.resv = 0; |
| 143 | fadt->x_gpe0_blk.addrl = pmbase + 0x20; |
| 144 | fadt->x_gpe0_blk.addrh = 0x0; |
| 145 | fadt->x_gpe1_blk.space_id = 0; |
| 146 | fadt->x_gpe1_blk.bit_width = 0; |
| 147 | fadt->x_gpe1_blk.bit_offset = 0; |
| 148 | fadt->x_gpe1_blk.resv = 0; |
| 149 | fadt->x_gpe1_blk.addrl = 0x0; |
| 150 | fadt->x_gpe1_blk.addrh = 0x0; |
| 151 | |
| 152 | header->checksum = table_compute_checksum((void *)fadt, header->length); |
| 153 | } |
| 154 | |
| 155 | unsigned long acpi_fill_madt(unsigned long current) |
| 156 | { |
| 157 | /* create all subtables for processors */ |
| 158 | current = acpi_create_madt_lapics(current); |
| 159 | |
| 160 | /* |
| 161 | * TODO(saket.sinha89@gmail.com): get these |
| 162 | * IRQ values from device tree |
| 163 | */ |
| 164 | current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, |
| 165 | 2, IO_APIC_ADDR, 0); |
| 166 | current += acpi_create_madt_irqoverride( |
| 167 | (struct acpi_madt_irqoverride *)current, 0, 0, 2, 0); |
| 168 | current += acpi_create_madt_irqoverride( |
| 169 | (struct acpi_madt_irqoverride *)current, 0, 9, 9, 0xd); |
| 170 | current += acpi_create_madt_irqoverride( |
| 171 | (struct acpi_madt_irqoverride *)current, 0, 0xd, 0xd, 0xd); |
| 172 | acpi_create_madt_lapic_nmi( |
| 173 | (struct acpi_madt_lapic_nmi *)current, 0, 0, 0); |
| 174 | |
| 175 | return current; |
| 176 | } |