blob: 3a2c6339d5e77dfed5622c97d086e6cfc0ab3df8 [file] [log] [blame]
Simon Glass61cc9332020-07-07 13:11:42 -06001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Core ACPI (Advanced Configuration and Power Interface) support
4 *
5 * Copyright 2019 Google LLC
6 *
7 * Modified from coreboot file acpigen.h
8 */
9
10#ifndef __ACPI_ACPIGEN_H
11#define __ACPI_ACPIGEN_H
12
13#include <linux/types.h>
14
15struct acpi_ctx;
Simon Glassd7d631d2020-07-07 21:32:11 -060016struct acpi_gen_regaddr;
Simon Glassf8054dd2020-07-07 13:12:01 -060017struct acpi_gpio;
Simon Glass61cc9332020-07-07 13:11:42 -060018
Simon Glass7e148f22020-07-07 13:11:50 -060019/* Top 4 bits of the value used to indicate a three-byte length value */
20#define ACPI_PKG_LEN_3_BYTES 0x80
21
Simon Glass9c70e7e2020-07-07 13:11:59 -060022#define ACPI_METHOD_NARGS_MASK 0x7
23#define ACPI_METHOD_SERIALIZED_MASK BIT(3)
24
Simon Glassd7d631d2020-07-07 21:32:11 -060025#define ACPI_END_TAG 0x79
26
Simon Glass03967ce2020-07-07 13:11:51 -060027/* ACPI Op/Prefix codes */
28enum {
Simon Glass83b2bd52020-07-07 13:11:52 -060029 ZERO_OP = 0x00,
30 ONE_OP = 0x01,
Simon Glass7aed90d2020-07-07 13:11:54 -060031 NAME_OP = 0x08,
Simon Glass83b2bd52020-07-07 13:11:52 -060032 BYTE_PREFIX = 0x0a,
33 WORD_PREFIX = 0x0b,
34 DWORD_PREFIX = 0x0c,
Simon Glass3df33bd2020-07-07 13:11:53 -060035 STRING_PREFIX = 0x0d,
Simon Glass83b2bd52020-07-07 13:11:52 -060036 QWORD_PREFIX = 0x0e,
Simon Glass82659cc2020-07-07 21:32:10 -060037 SCOPE_OP = 0x10,
Simon Glass29df8452020-07-07 13:11:55 -060038 BUFFER_OP = 0x11,
Simon Glass03967ce2020-07-07 13:11:51 -060039 PACKAGE_OP = 0x12,
Simon Glass9c70e7e2020-07-07 13:11:59 -060040 METHOD_OP = 0x14,
41 SLEEP_OP = 0x22,
Simon Glass7aed90d2020-07-07 13:11:54 -060042 DUAL_NAME_PREFIX = 0x2e,
43 MULTI_NAME_PREFIX = 0x2f,
Simon Glass9c70e7e2020-07-07 13:11:59 -060044 DEBUG_OP = 0x31,
45 EXT_OP_PREFIX = 0x5b,
Simon Glass0e5a0a02020-07-07 13:11:56 -060046 ROOT_PREFIX = 0x5c,
Simon Glass9c70e7e2020-07-07 13:11:59 -060047 LOCAL0_OP = 0x60,
48 LOCAL1_OP = 0x61,
49 LOCAL2_OP = 0x62,
50 LOCAL3_OP = 0x63,
51 LOCAL4_OP = 0x64,
52 LOCAL5_OP = 0x65,
53 LOCAL6_OP = 0x66,
54 LOCAL7_OP = 0x67,
Simon Glassda7cff32020-09-22 12:44:57 -060055 ARG0_OP = 0x68,
56 ARG1_OP = 0x69,
57 ARG2_OP = 0x6a,
58 ARG3_OP = 0x6b,
59 ARG4_OP = 0x6c,
60 ARG5_OP = 0x6d,
61 ARG6_OP = 0x6e,
Simon Glass9c70e7e2020-07-07 13:11:59 -060062 STORE_OP = 0x70,
63 AND_OP = 0x7b,
64 OR_OP = 0x7d,
65 NOT_OP = 0x80,
Simon Glass91c2f9c2020-07-07 21:32:14 -060066 DEVICE_OP = 0x82,
Simon Glass15403282020-09-22 12:45:11 -060067 PROCESSOR_OP = 0x83,
Simon Glassf9189d52020-07-07 13:12:00 -060068 POWER_RES_OP = 0x84,
Simon Glass15403282020-09-22 12:45:11 -060069 NOTIFY_OP = 0x86,
Simon Glassda7cff32020-09-22 12:44:57 -060070 LEQUAL_OP = 0x93,
71 TO_BUFFER_OP = 0x96,
72 TO_INTEGER_OP = 0x99,
73 IF_OP = 0xa0,
74 ELSE_OP = 0xa1,
Simon Glass9c70e7e2020-07-07 13:11:59 -060075 RETURN_OP = 0xa4,
Simon Glass03967ce2020-07-07 13:11:51 -060076};
77
Simon Glass61cc9332020-07-07 13:11:42 -060078/**
Simon Glass6c0da2d2020-09-22 12:45:08 -060079 * enum psd_coord - Coordination types for P-states
80 *
81 * The type of coordination that exists (hardware) or is required (software) as
82 * a result of the underlying hardware dependency
83 */
84enum psd_coord {
85 SW_ALL = 0xfc,
86 SW_ANY = 0xfd,
87 HW_ALL = 0xfe
88};
89
90/**
Simon Glass61cc9332020-07-07 13:11:42 -060091 * acpigen_get_current() - Get the current ACPI code output pointer
92 *
93 * @ctx: ACPI context pointer
94 * @return output pointer
95 */
96u8 *acpigen_get_current(struct acpi_ctx *ctx);
97
98/**
99 * acpigen_emit_byte() - Emit a byte to the ACPI code
100 *
101 * @ctx: ACPI context pointer
102 * @data: Value to output
103 */
104void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
105
106/**
107 * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
108 *
109 * @ctx: ACPI context pointer
110 * @data: Value to output
111 */
112void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
113
114/**
115 * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
116 *
117 * @ctx: ACPI context pointer
118 * @data: Value to output
119 */
120void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
121
Simon Glass7fb8da42020-07-07 13:11:45 -0600122/**
123 * acpigen_emit_stream() - Emit a stream of bytes
124 *
125 * @ctx: ACPI context pointer
126 * @data: Data to output
127 * @size: Size of data in bytes
128 */
129void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
130
131/**
132 * acpigen_emit_string() - Emit a string
133 *
134 * Emit a string with a null terminator
135 *
136 * @ctx: ACPI context pointer
137 * @str: String to output, or NULL for an empty string
138 */
139void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
140
Simon Glass7e148f22020-07-07 13:11:50 -0600141/**
142 * acpigen_write_len_f() - Write a 'forward' length placeholder
143 *
144 * This adds space for a length value in the ACPI stream and pushes the current
145 * position (before the length) on the stack. After calling this you can write
146 * some data and then call acpigen_pop_len() to update the length value.
147 *
148 * Usage:
149 *
150 * acpigen_write_len_f() ------\
151 * acpigen_write...() |
152 * acpigen_write...() |
153 * acpigen_write_len_f() --\ |
154 * acpigen_write...() | |
155 * acpigen_write...() | |
156 * acpigen_pop_len() ------/ |
157 * acpigen_write...() |
158 * acpigen_pop_len() ----------/
159 *
160 * See ACPI 6.3 section 20.2.4 Package Length Encoding
161 *
162 * This implementation always uses a 3-byte packet length for simplicity. It
163 * could be adjusted to support other lengths.
164 *
165 * @ctx: ACPI context pointer
166 */
167void acpigen_write_len_f(struct acpi_ctx *ctx);
168
169/**
170 * acpigen_pop_len() - Update the previously stacked length placeholder
171 *
172 * Call this after the data for the block has been written. It updates the
173 * top length value in the stack and pops it off.
174 *
175 * @ctx: ACPI context pointer
176 */
177void acpigen_pop_len(struct acpi_ctx *ctx);
178
Simon Glass03967ce2020-07-07 13:11:51 -0600179/**
180 * acpigen_write_package() - Start writing a package
181 *
182 * A package collects together a number of elements in the ACPI code. To write
183 * a package use:
184 *
185 * acpigen_write_package(ctx, 3);
186 * ...write things
187 * acpigen_pop_len()
188 *
189 * If you don't know the number of elements in advance, acpigen_write_package()
190 * returns a pointer to the value so you can update it later:
191 *
192 * char *num_elements = acpigen_write_package(ctx, 0);
193 * ...write things
194 * *num_elements += 1;
195 * ...write things
196 * *num_elements += 1;
197 * acpigen_pop_len()
198 *
199 * @ctx: ACPI context pointer
200 * @nr_el: Number of elements (0 if not known)
201 * @returns pointer to the number of elements, which can be updated by the
202 * caller if needed
203 */
204char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
205
Simon Glass83b2bd52020-07-07 13:11:52 -0600206/**
Simon Glassfea96512020-07-07 21:32:09 -0600207 * acpigen_write_byte() - Write a byte
208 *
209 * @ctx: ACPI context pointer
210 * @data: Value to write
211 */
212void acpigen_write_byte(struct acpi_ctx *ctx, unsigned int data);
213
214/**
215 * acpigen_write_word() - Write a word
216 *
217 * @ctx: ACPI context pointer
218 * @data: Value to write
219 */
220void acpigen_write_word(struct acpi_ctx *ctx, unsigned int data);
221
222/**
223 * acpigen_write_dword() - Write a dword
224 *
225 * @ctx: ACPI context pointer
226 * @data: Value to write
227 */
228void acpigen_write_dword(struct acpi_ctx *ctx, unsigned int data);
229
230/**
231 * acpigen_write_qword() - Write a qword
232 *
233 * @ctx: ACPI context pointer
234 * @data: Value to write
235 */
236void acpigen_write_qword(struct acpi_ctx *ctx, u64 data);
237
238/**
239 * acpigen_write_zero() - Write zero
240 *
241 * @ctx: ACPI context pointer
242 */
243void acpigen_write_zero(struct acpi_ctx *ctx);
244
245/**
246 * acpigen_write_one() - Write one
247 *
248 * @ctx: ACPI context pointer
249 */
250void acpigen_write_one(struct acpi_ctx *ctx);
251
252/**
Simon Glass83b2bd52020-07-07 13:11:52 -0600253 * acpigen_write_integer() - Write an integer
254 *
255 * This writes an operation (BYTE_OP, WORD_OP, DWORD_OP, QWORD_OP depending on
256 * the integer size) and an integer value. Note that WORD means 16 bits in ACPI.
257 *
258 * @ctx: ACPI context pointer
259 * @data: Integer to write
260 */
261void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
262
Simon Glass3df33bd2020-07-07 13:11:53 -0600263/**
Simon Glassbb6772c2020-07-07 21:32:15 -0600264 * acpigen_write_name_zero() - Write a named zero value
265 *
266 * @ctx: ACPI context pointer
267 * @name: Name of the value
268 */
269void acpigen_write_name_zero(struct acpi_ctx *ctx, const char *name);
270
271/**
272 * acpigen_write_name_one() - Write a named one value
273 *
274 * @ctx: ACPI context pointer
275 * @name: Name of the value
276 */
277void acpigen_write_name_one(struct acpi_ctx *ctx, const char *name);
278
279/**
280 * acpigen_write_name_byte() - Write a named byte value
281 *
282 * @ctx: ACPI context pointer
283 * @name: Name of the value
284 * @val: Value to write
285 */
286void acpigen_write_name_byte(struct acpi_ctx *ctx, const char *name, uint val);
287
288/**
289 * acpigen_write_name_word() - Write a named word value
290 *
291 * @ctx: ACPI context pointer
292 * @name: Name of the value
293 * @val: Value to write
294 */
295void acpigen_write_name_word(struct acpi_ctx *ctx, const char *name, uint val);
296
297/**
298 * acpigen_write_name_dword() - Write a named dword value
299 *
300 * @ctx: ACPI context pointer
301 * @name: Name of the value
302 * @val: Value to write
303 */
304void acpigen_write_name_dword(struct acpi_ctx *ctx, const char *name, uint val);
305
306/**
307 * acpigen_write_name_qword() - Write a named qword value
308 *
309 * @ctx: ACPI context pointer
310 * @name: Name of the value
311 * @val: Value to write
312 */
313void acpigen_write_name_qword(struct acpi_ctx *ctx, const char *name, u64 val);
314
315/**
316 * acpigen_write_name_integer() - Write a named integer value
317 *
318 * @ctx: ACPI context pointer
319 * @name: Name of the value
320 * @val: Value to write
321 */
322void acpigen_write_name_integer(struct acpi_ctx *ctx, const char *name,
323 u64 val);
324
325/**
326 * acpigen_write_name_string() - Write a named string value
327 *
328 * @ctx: ACPI context pointer
329 * @name: Name of the value
330 * @string: String to write
331 */
332void acpigen_write_name_string(struct acpi_ctx *ctx, const char *name,
333 const char *string);
334
335/**
Simon Glass3df33bd2020-07-07 13:11:53 -0600336 * acpigen_write_string() - Write a string
337 *
338 * This writes a STRING_PREFIX followed by a null-terminated string
339 *
340 * @ctx: ACPI context pointer
341 * @str: String to write
342 */
343void acpigen_write_string(struct acpi_ctx *ctx, const char *str);
Simon Glass7aed90d2020-07-07 13:11:54 -0600344
345/**
346 * acpigen_emit_namestring() - Emit an ACPI name
347 *
348 * This writes out an ACPI name or path in the required special format. It does
349 * not add the NAME_OP prefix.
350 *
351 * @ctx: ACPI context pointer
352 * @namepath: Name / path to emit
353 */
354void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);
355
356/**
357 * acpigen_write_name() - Write out an ACPI name
358 *
359 * This writes out an ACPI name or path in the required special format with a
360 * NAME_OP prefix.
361 *
362 * @ctx: ACPI context pointer
363 * @namepath: Name / path to emit
364 */
365void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);
Simon Glass29df8452020-07-07 13:11:55 -0600366
367/**
Simon Glass82659cc2020-07-07 21:32:10 -0600368 * acpigen_write_scope() - Write a scope
369 *
370 * @ctx: ACPI context pointer
371 * @scope: Scope to write (e.g. "\\_SB.ABCD")
372 */
373void acpigen_write_scope(struct acpi_ctx *ctx, const char *scope);
374
375/**
Simon Glass29df8452020-07-07 13:11:55 -0600376 * acpigen_write_uuid() - Write a UUID
377 *
378 * This writes out a UUID in the format used by ACPI, with a BUFFER_OP prefix.
379 *
380 * @ctx: ACPI context pointer
381 * @uuid: UUID to write in the form aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
382 * @return 0 if OK, -EINVAL if the format is incorrect
383 */
384int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid);
385
Simon Glass9c70e7e2020-07-07 13:11:59 -0600386/**
387 * acpigen_emit_ext_op() - Emit an extended op with the EXT_OP_PREFIX prefix
388 *
389 * @ctx: ACPI context pointer
390 * @op: Operation code (e.g. SLEEP_OP)
391 */
392void acpigen_emit_ext_op(struct acpi_ctx *ctx, uint op);
393
394/**
395 * acpigen_write_method() - Write a method header
396 *
397 * @ctx: ACPI context pointer
398 * @name: Method name (4 characters)
399 * @nargs: Number of method arguments (0 if none)
400 */
401void acpigen_write_method(struct acpi_ctx *ctx, const char *name, int nargs);
402
403/**
404 * acpigen_write_method_serialized() - Write a method header
405 *
406 * This sets the 'serialized' flag so that the method is thread-safe
407 *
408 * @ctx: ACPI context pointer
409 * @name: Method name (4 characters)
410 * @nargs: Number of method arguments (0 if none)
411 */
412void acpigen_write_method_serialized(struct acpi_ctx *ctx, const char *name,
413 int nargs);
414
415/**
Simon Glass91c2f9c2020-07-07 21:32:14 -0600416 * acpigen_write_device() - Write an ACPI device
417 *
418 * @ctx: ACPI context pointer
419 * @name: Device name to write
420 */
421void acpigen_write_device(struct acpi_ctx *ctx, const char *name);
422
423/**
Simon Glass9c70e7e2020-07-07 13:11:59 -0600424 * acpigen_write_sta() - Write a _STA method
425 *
426 * @ctx: ACPI context pointer
427 * @status: Status value to return
428 */
429void acpigen_write_sta(struct acpi_ctx *ctx, uint status);
430
431/**
Simon Glassd7d631d2020-07-07 21:32:11 -0600432 * acpigen_write_resourcetemplate_header() - Write a ResourceTemplate header
433 *
434 * @ctx: ACPI context pointer
435 */
436void acpigen_write_resourcetemplate_header(struct acpi_ctx *ctx);
437
438/**
439 * acpigen_write_resourcetemplate_footer() - Write a ResourceTemplate footer
440 *
441 * @ctx: ACPI context pointer
442 */
443void acpigen_write_resourcetemplate_footer(struct acpi_ctx *ctx);
444
445/**
446 * acpigen_write_register_resource() - Write a register resource
447 *
448 * This writes a header, the address information and a footer
449 *
450 * @ctx: ACPI context pointer
451 * @addr: Address to write
452 */
453void acpigen_write_register_resource(struct acpi_ctx *ctx,
454 const struct acpi_gen_regaddr *addr);
455
456/**
Simon Glass9c70e7e2020-07-07 13:11:59 -0600457 * acpigen_write_sleep() - Write a sleep operation
458 *
459 * @ctx: ACPI context pointer
460 * @sleep_ms: Number of milliseconds to sleep for
461 */
462void acpigen_write_sleep(struct acpi_ctx *ctx, u64 sleep_ms);
463
464/**
465 * acpigen_write_store() - Write a store operation
466 *
467 * @ctx: ACPI context pointer
468 */
469void acpigen_write_store(struct acpi_ctx *ctx);
470
471/**
472 * acpigen_write_debug_string() - Write a debug string
473 *
474 * This writes a debug operation with an associated string
475 *
476 * @ctx: ACPI context pointer
477 * @str: String to write
478 */
479void acpigen_write_debug_string(struct acpi_ctx *ctx, const char *str);
480
481/**
482 * acpigen_write_or() - Write a bitwise OR operation
483 *
484 * res = arg1 | arg2
485 *
486 * @ctx: ACPI context pointer
487 * @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP)
488 * @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP)
489 * @res: ACPI opcode for result (e.g. LOCAL2_OP)
490 */
491void acpigen_write_or(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res);
492
493/**
494 * acpigen_write_and() - Write a bitwise AND operation
495 *
496 * res = arg1 & arg2
497 *
498 * @ctx: ACPI context pointer
499 * @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP)
500 * @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP)
501 * @res: ACPI opcode for result (e.g. LOCAL2_OP)
502 */
503void acpigen_write_and(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res);
504
505/**
506 * acpigen_write_not() - Write a bitwise NOT operation
507 *
508 * res = ~arg1
509 *
510 * @ctx: ACPI context pointer
511 * @arg: ACPI opcode for operand (e.g. LOCAL0_OP)
512 * @res: ACPI opcode for result (e.g. LOCAL2_OP)
513 */
514void acpigen_write_not(struct acpi_ctx *ctx, u8 arg, u8 res);
515
Simon Glassf9189d52020-07-07 13:12:00 -0600516/**
517 * acpigen_write_power_res() - Write a power resource
518 *
519 * Name (_PRx, Package(One) { name })
520 * ...
521 * PowerResource (name, level, order)
522 *
523 * The caller should fill in the rest of the power resource and then call
524 * acpigen_pop_len() to close it off
525 *
526 * @ctx: ACPI context pointer
527 * @name: Name of power resource (e.g. "PRIC")
528 * @level: Deepest sleep level that this resource must be kept on (0=S0, 3=S3)
529 * @order: Order that this must be enabled/disabled (e.g. 0)
530 * @dev_stats: List of states to define, e.g. {"_PR0", "_PR3"}
531 * @dev_states_count: Number of dev states
532 */
533void acpigen_write_power_res(struct acpi_ctx *ctx, const char *name, uint level,
534 uint order, const char *const dev_states[],
535 size_t dev_states_count);
536
Simon Glassf8054dd2020-07-07 13:12:01 -0600537/**
538 * acpigen_set_enable_tx_gpio() - Emit ACPI code to enable/disable a GPIO
539 *
540 * This emits code to either enable to disable a Tx GPIO. It takes account of
541 * the GPIO polarity.
542 *
543 * The code needs access to the DW0 register for the pad being used. This is
544 * provided by gpio->pin0_addr and ACPI methods must be defined for the board
545 * which can read and write the pad's DW0 register given this address:
546 * @dw0_read: takes a single argument, the DW0 address
547 * returns the DW0 value
548 * @dw0:write: takes two arguments, the DW0 address and the value to write
549 * no return value
550 *
551 * Example code (-- means comment):
552 *
553 * -- Get Pad Configuration DW0 register value
554 * Method (GPC0, 0x1, Serialized)
555 * {
556 * -- Arg0 - GPIO DW0 address
557 * Store (Arg0, Local0)
558 * OperationRegion (PDW0, SystemMemory, Local0, 4)
559 * Field (PDW0, AnyAcc, NoLock, Preserve) {
560 * TEMP, 32
561 * }
562 * Return (TEMP)
563 * }
564 *
565 * -- Set Pad Configuration DW0 register value
566 * Method (SPC0, 0x2, Serialized)
567 * {
568 * -- Arg0 - GPIO DW0 address
569 * -- Arg1 - Value for DW0 register
570 * Store (Arg0, Local0)
571 * OperationRegion (PDW0, SystemMemory, Local0, 4)
572 * Field (PDW0, AnyAcc, NoLock, Preserve) {
573 * TEMP,32
574 * }
575 * Store (Arg1, TEMP)
576 * }
577 *
578 *
579 * @ctx: ACPI context pointer
580 * @tx_state_val: Mask to use to toggle the TX state on the GPIO pin, e,g.
581 * PAD_CFG0_TX_STATE
582 * @dw0_read: Method name to use to read dw0, e.g. "\\_SB.GPC0"
583 * @dw0_write: Method name to use to read dw0, e.g. "\\_SB.SPC0"
584 * @gpio: GPIO to change
585 * @enable: true to enable GPIO, false to disable
586 * Returns 0 on success, -ve on error.
587 */
588int acpigen_set_enable_tx_gpio(struct acpi_ctx *ctx, u32 tx_state_val,
589 const char *dw0_read, const char *dw0_write,
590 struct acpi_gpio *gpio, bool enable);
591
Simon Glasse0a896b2020-09-22 12:44:56 -0600592/**
593 * acpigen_write_prw() - Write a power resource for wake (_PRW)
594 *
595 * @ctx: ACPI context pointer
596 * @wake: GPE that wakes up the device
597 * @level: Deepest power system sleeping state that can be entered while still
598 * providing wake functionality
599 */
600void acpigen_write_prw(struct acpi_ctx *ctx, uint wake, uint level);
601
Simon Glassda7cff32020-09-22 12:44:57 -0600602/**
603 * acpigen_write_if() - Write an If block
604 *
605 * This requires a call to acpigen_pop_len() to complete the block
606 *
607 * @ctx: ACPI context pointer
608 */
609void acpigen_write_if(struct acpi_ctx *ctx);
610
611/**
612 * acpigen_write_if_lequal_op_int() - Write comparison between op and integer
613 *
614 * Generates ACPI code for checking if operand1 and operand2 are equal
615 *
616 * If (Lequal (op, val))
617 *
618 * @ctx: ACPI context pointer
619 * @op: Operand to check
620 * @val: Value to check against
621 */
622void acpigen_write_if_lequal_op_int(struct acpi_ctx *ctx, uint op, u64 val);
623
624/**
625 * acpigen_write_else() - Write an Ef block
626 *
627 * This requires a call to acpigen_pop_len() to complete the block
628 *
629 * @ctx: ACPI context pointer
630 */
631void acpigen_write_else(struct acpi_ctx *ctx);
632
633/**
634 * acpigen_write_to_buffer() - Write a ToBuffer operation
635 *
636 * E.g.: to generate: ToBuffer (Arg0, Local0)
637 * use acpigen_write_to_buffer(ctx, ARG0_OP, LOCAL0_OP)
638 *
639 * @ctx: ACPI context pointer
640 * @src: Source argument
641 * @dst: Destination argument
642 */
643void acpigen_write_to_buffer(struct acpi_ctx *ctx, uint src, uint dst);
644
645/**
646 * acpigen_write_to_integer() - Write a ToInteger operation
647 *
648 * E.g.: to generate: ToInteger (Arg0, Local0)
649 * use acpigen_write_to_integer(ctx, ARG0_OP, LOCAL0_OP)
650 *
651 * @ctx: ACPI context pointer
652 * @src: Source argument
653 * @dst: Destination argument
654 */
655void acpigen_write_to_integer(struct acpi_ctx *ctx, uint src, uint dst);
656
657/**
658 * acpigen_write_return_byte_buffer() - Write a return of a byte buffer
659 *
660 * @ctx: ACPI context pointer
661 * @arr: Array of bytes to return
662 * @size: Number of bytes
663 */
664void acpigen_write_return_byte_buffer(struct acpi_ctx *ctx, u8 *arr,
665 size_t size);
666
667/**
668 * acpigen_write_return_singleton_buffer() - Write a return of a 1-byte buffer
669 *
670 * @ctx: ACPI context pointer
671 * @arg: Byte to return
672 */
673void acpigen_write_return_singleton_buffer(struct acpi_ctx *ctx, uint arg);
674
675/**
676 * acpigen_write_return_byte() - Write a return of a byte
677 *
678 * @ctx: ACPI context pointer
679 * @arg: Byte to return
680 */
681void acpigen_write_return_byte(struct acpi_ctx *ctx, uint arg);
682
Simon Glass88490e12020-09-22 12:44:58 -0600683/**
684 * acpigen_write_dsm_start() - Start a _DSM method
685 *
686 * Generate ACPI AML code to start the _DSM method.
687 *
688 * The functions need to be called in the correct sequence as below.
689 *
690 * Within the <generate-code-here> region, Local0 and Local1 must be are left
691 * untouched, but Local2-Local7 can be used
692 *
693 * Arguments passed into _DSM method:
694 * Arg0 = UUID
695 * Arg1 = Revision
696 * Arg2 = Function index
697 * Arg3 = Function-specific arguments
698 *
699 * AML code generated looks like this:
700 * Method (_DSM, 4, Serialized) { -- acpigen_write_dsm_start)
701 * ToBuffer (Arg0, Local0)
702 * If (LEqual (Local0, ToUUID(uuid))) { -- acpigen_write_dsm_uuid_start
703 * ToInteger (Arg2, Local1)
704 * If (LEqual (Local1, 0)) { -- acpigen_write_dsm_uuid_start_cond
705 * <generate-code-here>
706 * } -- acpigen_write_dsm_uuid_end_cond
707 * ...
708 * If (LEqual (Local1, n)) { -- acpigen_write_dsm_uuid_start_cond
709 * <generate-code-here>
710 * } -- acpigen_write_dsm_uuid_end_cond
711 * Return (Buffer (One) { 0x0 })
712 * } -- acpigen_write_dsm_uuid_end
713 * ...
714 * If (LEqual (Local0, ToUUID(uuidn))) {
715 * ...
716 * }
717 * Return (Buffer (One) { 0x0 }) -- acpigen_write_dsm_end
718 * }
719 *
720 * @ctx: ACPI context pointer
721 */
722void acpigen_write_dsm_start(struct acpi_ctx *ctx);
723
724/**
725 * acpigen_write_dsm_uuid_start() - Start a new UUID block
726 *
727 * This starts generation of code to handle a particular UUID:
728 *
729 * If (LEqual (Local0, ToUUID(uuid))) {
730 * ToInteger (Arg2, Local1)
731 *
732 * @ctx: ACPI context pointer
733 */
734int acpigen_write_dsm_uuid_start(struct acpi_ctx *ctx, const char *uuid);
735
736/**
737 * acpigen_write_dsm_uuid_start_cond() - Start a new condition block
738 *
739 * This starts generation of condition-checking code to handle a particular
740 * function:
741 *
742 * If (LEqual (Local1, i))
743 *
744 * @ctx: ACPI context pointer
745 */
746void acpigen_write_dsm_uuid_start_cond(struct acpi_ctx *ctx, int seq);
747
748/**
749 * acpigen_write_dsm_uuid_end_cond() - Start a new condition block
750 *
751 * This ends generation of condition-checking code to handle a particular
752 * function:
753 *
754 * }
755 *
756 * @ctx: ACPI context pointer
757 */
758void acpigen_write_dsm_uuid_end_cond(struct acpi_ctx *ctx);
759
760/**
761 * acpigen_write_dsm_uuid_end() - End a UUID block
762 *
763 * This ends generation of code to handle a particular UUID:
764 *
765 * Return (Buffer (One) { 0x0 })
766 *
767 * @ctx: ACPI context pointer
768 */
769void acpigen_write_dsm_uuid_end(struct acpi_ctx *ctx);
770
771/**
772 * acpigen_write_dsm_end() - End a _DSM method
773 *
774 * This ends generates of the _DSM block:
775 *
776 * Return (Buffer (One) { 0x0 })
777 *
778 * @ctx: ACPI context pointer
779 */
780void acpigen_write_dsm_end(struct acpi_ctx *ctx);
781
Simon Glass15403282020-09-22 12:45:11 -0600782/**
783 * acpigen_write_processor() - Write a Processor package
784 *
785 * This emits a Processor package header with the required information. The
786 * caller must complete the information and call acpigen_pop_len() at the end
787 *
788 * @ctx: ACPI context pointer
789 * @cpuindex: CPU number
790 * @pblock_addr: PBlk system IO address
791 * @pblock_len: PBlk length
792 */
793void acpigen_write_processor(struct acpi_ctx *ctx, uint cpuindex,
794 u32 pblock_addr, uint pblock_len);
795
796/**
797 * acpigen_write_processor_package() - Write a package containing the processors
798 *
799 * The package containins the name of each processor in the SoC
800 *
801 * @ctx: ACPI context pointer
802 * @name: Package name (.e.g "PPKG")
803 * @first_core: Number of the first core (e.g. 0)
804 * @core_count: Number of cores (e.g. 4)
805 */
806void acpigen_write_processor_package(struct acpi_ctx *ctx, const char *name,
807 uint first_core, uint core_count);
808
809/**
810 * acpigen_write_processor_cnot() - Write a processor notification method
811 *
812 * This writes a method that notifies all CPU cores
813 *
814 * @ctx: ACPI context pointer
815 * @num_cores: Number of CPU cores
816 */
817void acpigen_write_processor_cnot(struct acpi_ctx *ctx, const uint num_cores);
818
Simon Glass61cc9332020-07-07 13:11:42 -0600819#endif