blob: 1d54f7dba1a41e300000a6000b1e4473328a1b45 [file] [log] [blame]
Bin Meng4470f2d2016-05-07 07:46:32 -07001/*
2 * Copyright (C) 2016, Bin Meng <bmeng.cn@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/mpspec.h>
11#include <asm/tables.h>
12#include <asm/arch/iomap.h>
13
14void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
15 void *dsdt)
16{
17 struct acpi_table_header *header = &(fadt->header);
18 u16 pmbase = ACPI_BASE_ADDRESS;
19
20 memset((void *)fadt, 0, sizeof(struct acpi_fadt));
21
22 acpi_fill_header(header, "FACP");
23 header->length = sizeof(struct acpi_fadt);
24 header->revision = 4;
25
26 fadt->firmware_ctrl = (u32)facs;
27 fadt->dsdt = (u32)dsdt;
28 fadt->preferred_pm_profile = ACPI_PM_MOBILE;
29 fadt->sci_int = 9;
30 fadt->smi_cmd = 0;
31 fadt->acpi_enable = 0;
32 fadt->acpi_disable = 0;
33 fadt->s4bios_req = 0;
34 fadt->pstate_cnt = 0;
35 fadt->pm1a_evt_blk = pmbase;
36 fadt->pm1b_evt_blk = 0x0;
37 fadt->pm1a_cnt_blk = pmbase + 0x4;
38 fadt->pm1b_cnt_blk = 0x0;
39 fadt->pm2_cnt_blk = pmbase + 0x50;
40 fadt->pm_tmr_blk = pmbase + 0x8;
41 fadt->gpe0_blk = pmbase + 0x20;
42 fadt->gpe1_blk = 0;
43 fadt->pm1_evt_len = 4;
44 fadt->pm1_cnt_len = 2;
45 fadt->pm2_cnt_len = 1;
46 fadt->pm_tmr_len = 4;
47 fadt->gpe0_blk_len = 8;
48 fadt->gpe1_blk_len = 0;
49 fadt->gpe1_base = 0;
50 fadt->cst_cnt = 0;
51 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
52 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
53 fadt->flush_size = 0;
54 fadt->flush_stride = 0;
55 fadt->duty_offset = 1;
56 fadt->duty_width = 0;
57 fadt->day_alrm = 0x0d;
58 fadt->mon_alrm = 0x00;
59 fadt->century = 0x00;
60 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
61 fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
62 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
63 ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_RESET_REGISTER |
64 ACPI_FADT_PLATFORM_CLOCK;
65
66 fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
67 fadt->reset_reg.bit_width = 8;
68 fadt->reset_reg.bit_offset = 0;
69 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
70 fadt->reset_reg.addrl = IO_PORT_RESET;
71 fadt->reset_reg.addrh = 0;
72 fadt->reset_value = SYS_RST | RST_CPU;
73
74 fadt->x_firmware_ctl_l = (u32)facs;
75 fadt->x_firmware_ctl_h = 0;
76 fadt->x_dsdt_l = (u32)dsdt;
77 fadt->x_dsdt_h = 0;
78
79 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
80 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
81 fadt->x_pm1a_evt_blk.bit_offset = 0;
82 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
83 fadt->x_pm1a_evt_blk.addrl = fadt->pm1a_evt_blk;
84 fadt->x_pm1a_evt_blk.addrh = 0x0;
85
86 fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
87 fadt->x_pm1b_evt_blk.bit_width = 0;
88 fadt->x_pm1b_evt_blk.bit_offset = 0;
89 fadt->x_pm1b_evt_blk.access_size = 0;
90 fadt->x_pm1b_evt_blk.addrl = 0x0;
91 fadt->x_pm1b_evt_blk.addrh = 0x0;
92
93 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
94 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
95 fadt->x_pm1a_cnt_blk.bit_offset = 0;
96 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
97 fadt->x_pm1a_cnt_blk.addrl = fadt->pm1a_cnt_blk;
98 fadt->x_pm1a_cnt_blk.addrh = 0x0;
99
100 fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
101 fadt->x_pm1b_cnt_blk.bit_width = 0;
102 fadt->x_pm1b_cnt_blk.bit_offset = 0;
103 fadt->x_pm1b_cnt_blk.access_size = 0;
104 fadt->x_pm1b_cnt_blk.addrl = 0x0;
105 fadt->x_pm1b_cnt_blk.addrh = 0x0;
106
107 fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
108 fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8;
109 fadt->x_pm2_cnt_blk.bit_offset = 0;
110 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
111 fadt->x_pm2_cnt_blk.addrl = fadt->pm2_cnt_blk;
112 fadt->x_pm2_cnt_blk.addrh = 0x0;
113
114 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
115 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
116 fadt->x_pm_tmr_blk.bit_offset = 0;
117 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
118 fadt->x_pm_tmr_blk.addrl = fadt->pm_tmr_blk;
119 fadt->x_pm_tmr_blk.addrh = 0x0;
120
121 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
122 fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
123 fadt->x_gpe0_blk.bit_offset = 0;
124 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
125 fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
126 fadt->x_gpe0_blk.addrh = 0x0;
127
128 fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO;
129 fadt->x_gpe1_blk.bit_width = 0;
130 fadt->x_gpe1_blk.bit_offset = 0;
131 fadt->x_gpe1_blk.access_size = 0;
132 fadt->x_gpe1_blk.addrl = 0x0;
133 fadt->x_gpe1_blk.addrh = 0x0;
134
135 header->checksum = table_compute_checksum(fadt, header->length);
136}
137
138static int acpi_create_madt_irq_overrides(u32 current)
139{
140 struct acpi_madt_irqoverride *irqovr;
141 u16 sci_flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH;
142 int length = 0;
143
144 irqovr = (void *)current;
145 length += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
146
147 irqovr = (void *)(current + length);
148 length += acpi_create_madt_irqoverride(irqovr, 0, 9, 9, sci_flags);
149
150 return length;
151}
152
153u32 acpi_fill_madt(u32 current)
154{
155 current += acpi_create_madt_lapics(current);
156
157 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
158 2, IO_APIC_ADDR, 0);
159
160 current += acpi_create_madt_irq_overrides(current);
161
162 return current;
163}