Debian Codegraph @

src/soc/amd/cezanne/acpi.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 /* ACPI - create the Fixed ACPI Description Tables (FADT) */
4
5 #include <acpi/acpi.h>
6 #include <acpi/acpigen.h>
7 #include <amdblocks/acp.h>
8 #include <amdblocks/acpi.h>
9 #include <amdblocks/cppc.h>
10 #include <amdblocks/cpu.h>
11 #include <amdblocks/acpimmio.h>
12 #include <amdblocks/ioapic.h>
13 #include <arch/ioapic.h>
14 #include <arch/smp/mpspec.h>
15 #include <console/console.h>
16 #include <cpu/amd/cpuid.h>
17 #include <device/device.h>
18 #include <soc/iomap.h>
19 #include <static.h>
20 #include <types.h>
21 #include "chip.h"
22
23 /*
24 * Reference section 5.2.9 Fixed ACPI Description Table (FADT)
25 * in the ACPI 3.0b specification.
26 */
27 void acpi_fill_fadt(acpi_fadt_t *fadt)
28 {
29 const struct soc_amd_cezanne_config *cfg = config_of_soc();
30
31 printk(BIOS_DEBUG, "pm_base: 0x%04x\n", ACPI_IO_BASE);
32
33 fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK;
34 fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK;
35 fadt->pm_tmr_blk = ACPI_PM_TMR_BLK;
36 fadt->gpe0_blk = ACPI_GPE0_BLK;
37
38 fadt->pm1_evt_len = 4; /* 32 bits */
39 fadt->pm1_cnt_len = 2; /* 16 bits */
40 fadt->pm_tmr_len = 4; /* 32 bits */
41 fadt->gpe0_blk_len = 8; /* 64 bits */
42
43 fill_fadt_extended_pm_io(fadt);
44
45 fadt->iapc_boot_arch = cfg->common_config.fadt_boot_arch; /* legacy free default */
46 fadt->flags |= ACPI_FADT_WBINVD | /* See table 5-34 ACPI 6.3 spec */
47 ACPI_FADT_C1_SUPPORTED |
48 ACPI_FADT_S4_RTC_WAKE |
49 ACPI_FADT_32BIT_TIMER |
50 ACPI_FADT_PCI_EXPRESS_WAKE |
51 ACPI_FADT_PLATFORM_CLOCK |
52 ACPI_FADT_S4_RTC_VALID |
53 ACPI_FADT_REMOTE_POWER_ON;
54 if (cfg->s0ix_enable)
55 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
56
57 fadt->flags |= cfg->common_config.fadt_flags; /* additional board-specific flags */
58 }
59
60 unsigned long soc_acpi_write_tables(const struct device *device, unsigned long current,
61 acpi_rsdp_t *rsdp)
62 {
63 /* IVRS */
64 current = acpi_add_ivrs_table(current, rsdp);
65
66 if (CONFIG(PLATFORM_USES_FSP2_0))
67 current = acpi_add_fsp_tables(current, rsdp);
68
69 return current;
70 }
71
72 const acpi_cstate_t cstate_cfg_table[] = {
73 [0] = {
74 .ctype = 1,
75 .latency = 1,
76 .power = 0,
77 },
78 [1] = {
79 .ctype = 2,
80 .latency = 0x12,
81 .power = 0,
82 },
83 [2] = {
84 .ctype = 3,
85 .latency = 350,
86 .power = 0,
87 },
88 };
89
90 const acpi_cstate_t *get_cstate_config_data(size_t *size)
91 {
92 *size = ARRAY_SIZE(cstate_cfg_table);
93 return cstate_cfg_table;
94 }
95
96 static void acp_soc_write_smn_access_methods(void)
97 {
98 acpigen_write_method_serialized("SMNR", 1);
99 acpigen_write_store_op_to_namestr(ARG0_OP, "\\_SB.PCI0.GNB.SMNA");
100 acpigen_write_return_namestr("\\_SB.PCI0.GNB.SMND");
101 acpigen_write_method_end();
102
103 acpigen_write_method_serialized("SMNW", 2);
104 acpigen_write_store_op_to_namestr(ARG0_OP, "\\_SB.PCI0.GNB.SMNA");
105 acpigen_write_store_op_to_namestr(ARG1_OP, "\\_SB.PCI0.GNB.SMND");
106 acpigen_write_method_end();
107 }
108
109 /* write value of ACPI variable into SMN register */
110 static void acp_soc_write_smn_register_write(uint8_t op, uint32_t smn_address)
111 {
112 acpigen_emit_namestring("^SMNW");
113 acpigen_write_integer(smn_address);
114 acpigen_emit_byte(op);
115 }
116
117 /* read SMN register and store value into ACPI variable */
118 static void acp_soc_write_smn_register_read(uint32_t smn_address, uint8_t op)
119 {
120 acpigen_write_store();
121 acpigen_emit_namestring("^SMNR");
122 acpigen_write_integer(smn_address);
123 acpigen_emit_byte(op);
124 }
125
126 static void acp_soc_write_mailbox_access(void)
127 {
128 acp_soc_write_smn_register_write(ARG0_OP, 0x00058A74);
129 acp_soc_write_smn_register_write(ARG1_OP, 0x00058A54);
130 acp_soc_write_smn_register_write(ARG2_OP, 0x00058A14);
131 acp_soc_write_smn_register_read(0x00058A74, LOCAL0_OP);
132
133 /* While (LEqual (Local0, 0)) */
134 acpigen_emit_byte(WHILE_OP);
135 acpigen_write_len_f();
136 acpigen_emit_byte(LEQUAL_OP);
137 acpigen_emit_byte(LOCAL0_OP);
138 acpigen_emit_byte(ZERO_OP);
139
140 acp_soc_write_smn_register_read(0x00058A74, LOCAL0_OP);
141
142 acpigen_pop_len(); /* While */
143
144 acp_soc_write_smn_register_read(0x00058A54, LOCAL1_OP);
145
146 acpigen_write_return_op(LOCAL1_OP);
147 }
148
149 static void acp_soc_write_psp_mbox_buffer_field(void)
150 {
151 acpigen_write_name("MBOX");
152 acpigen_write_byte_buffer(NULL, 4);
153 acpigen_write_create_buffer_word_field("MBOX", 0, "STAT");
154 acpigen_write_create_buffer_byte_field("MBOX", 2, "CMDI");
155 acpigen_write_create_buffer_bit_field("MBOX", 31, "REDY");
156 }
157
158 static void acp_soc_write_psp_read_mbox_from_hw(void)
159 {
160 acp_soc_write_smn_register_read(0x03810570, LOCAL0_OP);
161 acpigen_write_store_op_to_namestr(LOCAL0_OP, "MBOX");
162 }
163
164 static void acp_soc_write_psp_write_mbox_to_hw(void)
165 {
166 acpigen_write_store_namestr_to_op("MBOX", LOCAL0_OP);
167 acp_soc_write_smn_register_write(LOCAL0_OP, 0x03810570);
168 }
169
170 static void acp_soc_write_psp_mailbox_access(void)
171 {
172
173 acp_soc_write_psp_mbox_buffer_field();
174
175 acp_soc_write_psp_read_mbox_from_hw();
176
177 /* While (LOr (LNotEqual (REDY, 0x1), LNotEqual (CMDI, 0x00))) */
178 acpigen_emit_byte(WHILE_OP);
179 acpigen_write_len_f();
180 acpigen_emit_byte(LOR_OP);
181 acpigen_emit_byte(LNOT_OP);
182 acpigen_emit_byte(LEQUAL_OP);
183 acpigen_emit_namestring("REDY");
184 acpigen_write_integer(1);
185 acpigen_emit_byte(LNOT_OP);
186 acpigen_emit_byte(LEQUAL_OP);
187 acpigen_emit_namestring("CMDI");
188 acpigen_write_integer(0);
189
190 acp_soc_write_psp_read_mbox_from_hw();
191
192 acpigen_pop_len(); /* While */
193
194 acpigen_write_store_int_to_op(0, LOCAL0_OP);
195 acpigen_write_store_op_to_namestr(LOCAL0_OP, "MBOX");
196 acpigen_write_store_int_to_namestr(0x33, "CMDI");
197
198 acp_soc_write_psp_write_mbox_to_hw();
199
200 acpigen_write_sleep(1);
201
202 acp_soc_write_psp_read_mbox_from_hw();
203
204 /* While (LNotEqual (CMDI, 0x00)) */
205 acpigen_emit_byte(WHILE_OP);
206 acpigen_write_len_f();
207 acpigen_emit_byte(LNOT_OP);
208 acpigen_emit_byte(LEQUAL_OP);
209 acpigen_emit_namestring("CMDI");
210 acpigen_write_integer(0);
211
212 acp_soc_write_psp_read_mbox_from_hw();
213
214 acpigen_pop_len(); /* While */
215
216 acpigen_write_return_op(LOCAL0_OP);
217 }
218
219 static void acp_soc_write_msg0_method(void)
220 {
221 acpigen_write_method_serialized("MSG0", 3);
222
223 /* If (ARG2 != 0x9) */
224 acpigen_write_if_lnotequal_op_int(ARG2_OP, 0x9);
225
226 acp_soc_write_mailbox_access();
227
228 acpigen_write_else();
229
230 acp_soc_write_psp_mailbox_access();
231
232 acpigen_write_if_end();
233
234 acpigen_write_method_end(); /* MSG0 */
235 }
236
237 void acp_soc_write_ssdt_entry(const struct device *dev)
238 {
239 /*
240 * SMN and mailbox interface using the SMN OperationRegion on the host bridge
241 *
242 * Provide both SMN read/write methods for direct SMN register access and the MSG0
243 * method which is used by some ACP drivers to access two different mailbox interfaces
244 * in the hardware. One mailbox interface is used to configure the ACP's clock source,
245 * the other one is used to notify the PSP that the DSP firmware has been loaded, so
246 * that the PSP can validate the firmware and set the qualifier bit to enable running
247 * it.
248 *
249 * Scope (\_SB.PCI0.GP41.ACPD)
250 * {
251 * Method (SMNR, 1, Serialized)
252 * {
253 * Store (Arg0, \_SB.PCI0.GNB.SMNA)
254 * Return (\_SB.PCI0.GNB.SMND)
255 * }
256 *
257 * Method (SMNW, 2, Serialized)
258 * {
259 * Store (Arg0, \_SB.PCI0.GNB.SMNA)
260 * Store (Arg1, \_SB.PCI0.GNB.SMND)
261 * }
262 *
263 * Method (MSG0, 3, Serialized)
264 * {
265 * If (LNotEqual (Arg2, 0x09))
266 * {
267 * ^SMNW (0x00058A74, Arg0)
268 * ^SMNW (0x00058A54, Arg1)
269 * ^SMNW (0x00058A14, Arg2)
270 * Store (^SMNR (0x00058A74), Local0)
271 * While (LEqual (Local0, Zero))
272 * {
273 * Store (^SMNR (0x00058A74), Local0)
274 * }
275 * Store (^SMNR (0x00058A54), Local1)
276 * Return (Local1)
277 * }
278 * Else
279 * {
280 * Name (MBOX, Buffer (0x04){})
281 * CreateWordField (MBOX, Zero, STAT)
282 * CreateByteField (MBOX, 0x02, CMDI)
283 * CreateBitField (MBOX, 0x1F, REDY)
284 * Store (^SMNR (0x03810570), Local0)
285 * Store (Local0, MBOX)
286 * While (LOr (LNotEqual (REDY, One), LNotEqual (CMDI, Zero)))
287 * {
288 * Store (^SMNR (0x03810570), Local0)
289 * Store (Local0, MBOX)
290 * }
291 * Store (Zero, Local0)
292 * Store (Local0, MBOX)
293 * Store (0x33, CMDI)
294 * Store (MBOX, Local0)
295 * ^SMNW (0x03810570, Local0)
296 * Sleep (One)
297 * Store (^SMNR (0x03810570), Local0)
298 * Store (Local0, MBOX)
299 * While (LNotEqual (CMDI, Zero))
300 * {
301 * Store (^SMNR (0x03810570), Local0)
302 * Store (Local0, MBOX)
303 * }
304 * Return (Local0)
305 * }
306 * }
307 * }
308 */
309
310 acpigen_write_scope(acpi_device_path(dev));
311
312 acp_soc_write_smn_access_methods();
313
314 acp_soc_write_msg0_method();
315
316 acpigen_write_scope_end();
317 }