blob: 34b3115bc9c140a99d4d4bafc6399009b275918c [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 Glassf9189d52020-07-07 13:12:00 -060067 POWER_RES_OP = 0x84,
Simon Glassda7cff32020-09-22 12:44:57 -060068 LEQUAL_OP = 0x93,
69 TO_BUFFER_OP = 0x96,
70 TO_INTEGER_OP = 0x99,
71 IF_OP = 0xa0,
72 ELSE_OP = 0xa1,
Simon Glass9c70e7e2020-07-07 13:11:59 -060073 RETURN_OP = 0xa4,
Simon Glass03967ce2020-07-07 13:11:51 -060074};
75
Simon Glass61cc9332020-07-07 13:11:42 -060076/**
77 * acpigen_get_current() - Get the current ACPI code output pointer
78 *
79 * @ctx: ACPI context pointer
80 * @return output pointer
81 */
82u8 *acpigen_get_current(struct acpi_ctx *ctx);
83
84/**
85 * acpigen_emit_byte() - Emit a byte to the ACPI code
86 *
87 * @ctx: ACPI context pointer
88 * @data: Value to output
89 */
90void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
91
92/**
93 * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
94 *
95 * @ctx: ACPI context pointer
96 * @data: Value to output
97 */
98void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
99
100/**
101 * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
102 *
103 * @ctx: ACPI context pointer
104 * @data: Value to output
105 */
106void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
107
Simon Glass7fb8da42020-07-07 13:11:45 -0600108/**
109 * acpigen_emit_stream() - Emit a stream of bytes
110 *
111 * @ctx: ACPI context pointer
112 * @data: Data to output
113 * @size: Size of data in bytes
114 */
115void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
116
117/**
118 * acpigen_emit_string() - Emit a string
119 *
120 * Emit a string with a null terminator
121 *
122 * @ctx: ACPI context pointer
123 * @str: String to output, or NULL for an empty string
124 */
125void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
126
Simon Glass7e148f22020-07-07 13:11:50 -0600127/**
128 * acpigen_write_len_f() - Write a 'forward' length placeholder
129 *
130 * This adds space for a length value in the ACPI stream and pushes the current
131 * position (before the length) on the stack. After calling this you can write
132 * some data and then call acpigen_pop_len() to update the length value.
133 *
134 * Usage:
135 *
136 * acpigen_write_len_f() ------\
137 * acpigen_write...() |
138 * acpigen_write...() |
139 * acpigen_write_len_f() --\ |
140 * acpigen_write...() | |
141 * acpigen_write...() | |
142 * acpigen_pop_len() ------/ |
143 * acpigen_write...() |
144 * acpigen_pop_len() ----------/
145 *
146 * See ACPI 6.3 section 20.2.4 Package Length Encoding
147 *
148 * This implementation always uses a 3-byte packet length for simplicity. It
149 * could be adjusted to support other lengths.
150 *
151 * @ctx: ACPI context pointer
152 */
153void acpigen_write_len_f(struct acpi_ctx *ctx);
154
155/**
156 * acpigen_pop_len() - Update the previously stacked length placeholder
157 *
158 * Call this after the data for the block has been written. It updates the
159 * top length value in the stack and pops it off.
160 *
161 * @ctx: ACPI context pointer
162 */
163void acpigen_pop_len(struct acpi_ctx *ctx);
164
Simon Glass03967ce2020-07-07 13:11:51 -0600165/**
166 * acpigen_write_package() - Start writing a package
167 *
168 * A package collects together a number of elements in the ACPI code. To write
169 * a package use:
170 *
171 * acpigen_write_package(ctx, 3);
172 * ...write things
173 * acpigen_pop_len()
174 *
175 * If you don't know the number of elements in advance, acpigen_write_package()
176 * returns a pointer to the value so you can update it later:
177 *
178 * char *num_elements = acpigen_write_package(ctx, 0);
179 * ...write things
180 * *num_elements += 1;
181 * ...write things
182 * *num_elements += 1;
183 * acpigen_pop_len()
184 *
185 * @ctx: ACPI context pointer
186 * @nr_el: Number of elements (0 if not known)
187 * @returns pointer to the number of elements, which can be updated by the
188 * caller if needed
189 */
190char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
191
Simon Glass83b2bd52020-07-07 13:11:52 -0600192/**
Simon Glassfea96512020-07-07 21:32:09 -0600193 * acpigen_write_byte() - Write a byte
194 *
195 * @ctx: ACPI context pointer
196 * @data: Value to write
197 */
198void acpigen_write_byte(struct acpi_ctx *ctx, unsigned int data);
199
200/**
201 * acpigen_write_word() - Write a word
202 *
203 * @ctx: ACPI context pointer
204 * @data: Value to write
205 */
206void acpigen_write_word(struct acpi_ctx *ctx, unsigned int data);
207
208/**
209 * acpigen_write_dword() - Write a dword
210 *
211 * @ctx: ACPI context pointer
212 * @data: Value to write
213 */
214void acpigen_write_dword(struct acpi_ctx *ctx, unsigned int data);
215
216/**
217 * acpigen_write_qword() - Write a qword
218 *
219 * @ctx: ACPI context pointer
220 * @data: Value to write
221 */
222void acpigen_write_qword(struct acpi_ctx *ctx, u64 data);
223
224/**
225 * acpigen_write_zero() - Write zero
226 *
227 * @ctx: ACPI context pointer
228 */
229void acpigen_write_zero(struct acpi_ctx *ctx);
230
231/**
232 * acpigen_write_one() - Write one
233 *
234 * @ctx: ACPI context pointer
235 */
236void acpigen_write_one(struct acpi_ctx *ctx);
237
238/**
Simon Glass83b2bd52020-07-07 13:11:52 -0600239 * acpigen_write_integer() - Write an integer
240 *
241 * This writes an operation (BYTE_OP, WORD_OP, DWORD_OP, QWORD_OP depending on
242 * the integer size) and an integer value. Note that WORD means 16 bits in ACPI.
243 *
244 * @ctx: ACPI context pointer
245 * @data: Integer to write
246 */
247void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
248
Simon Glass3df33bd2020-07-07 13:11:53 -0600249/**
Simon Glassbb6772c2020-07-07 21:32:15 -0600250 * acpigen_write_name_zero() - Write a named zero value
251 *
252 * @ctx: ACPI context pointer
253 * @name: Name of the value
254 */
255void acpigen_write_name_zero(struct acpi_ctx *ctx, const char *name);
256
257/**
258 * acpigen_write_name_one() - Write a named one value
259 *
260 * @ctx: ACPI context pointer
261 * @name: Name of the value
262 */
263void acpigen_write_name_one(struct acpi_ctx *ctx, const char *name);
264
265/**
266 * acpigen_write_name_byte() - Write a named byte value
267 *
268 * @ctx: ACPI context pointer
269 * @name: Name of the value
270 * @val: Value to write
271 */
272void acpigen_write_name_byte(struct acpi_ctx *ctx, const char *name, uint val);
273
274/**
275 * acpigen_write_name_word() - Write a named word value
276 *
277 * @ctx: ACPI context pointer
278 * @name: Name of the value
279 * @val: Value to write
280 */
281void acpigen_write_name_word(struct acpi_ctx *ctx, const char *name, uint val);
282
283/**
284 * acpigen_write_name_dword() - Write a named dword value
285 *
286 * @ctx: ACPI context pointer
287 * @name: Name of the value
288 * @val: Value to write
289 */
290void acpigen_write_name_dword(struct acpi_ctx *ctx, const char *name, uint val);
291
292/**
293 * acpigen_write_name_qword() - Write a named qword value
294 *
295 * @ctx: ACPI context pointer
296 * @name: Name of the value
297 * @val: Value to write
298 */
299void acpigen_write_name_qword(struct acpi_ctx *ctx, const char *name, u64 val);
300
301/**
302 * acpigen_write_name_integer() - Write a named integer value
303 *
304 * @ctx: ACPI context pointer
305 * @name: Name of the value
306 * @val: Value to write
307 */
308void acpigen_write_name_integer(struct acpi_ctx *ctx, const char *name,
309 u64 val);
310
311/**
312 * acpigen_write_name_string() - Write a named string value
313 *
314 * @ctx: ACPI context pointer
315 * @name: Name of the value
316 * @string: String to write
317 */
318void acpigen_write_name_string(struct acpi_ctx *ctx, const char *name,
319 const char *string);
320
321/**
Simon Glass3df33bd2020-07-07 13:11:53 -0600322 * acpigen_write_string() - Write a string
323 *
324 * This writes a STRING_PREFIX followed by a null-terminated string
325 *
326 * @ctx: ACPI context pointer
327 * @str: String to write
328 */
329void acpigen_write_string(struct acpi_ctx *ctx, const char *str);
Simon Glass7aed90d2020-07-07 13:11:54 -0600330
331/**
332 * acpigen_emit_namestring() - Emit an ACPI name
333 *
334 * This writes out an ACPI name or path in the required special format. It does
335 * not add the NAME_OP prefix.
336 *
337 * @ctx: ACPI context pointer
338 * @namepath: Name / path to emit
339 */
340void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);
341
342/**
343 * acpigen_write_name() - Write out an ACPI name
344 *
345 * This writes out an ACPI name or path in the required special format with a
346 * NAME_OP prefix.
347 *
348 * @ctx: ACPI context pointer
349 * @namepath: Name / path to emit
350 */
351void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);
Simon Glass29df8452020-07-07 13:11:55 -0600352
353/**
Simon Glass82659cc2020-07-07 21:32:10 -0600354 * acpigen_write_scope() - Write a scope
355 *
356 * @ctx: ACPI context pointer
357 * @scope: Scope to write (e.g. "\\_SB.ABCD")
358 */
359void acpigen_write_scope(struct acpi_ctx *ctx, const char *scope);
360
361/**
Simon Glass29df8452020-07-07 13:11:55 -0600362 * acpigen_write_uuid() - Write a UUID
363 *
364 * This writes out a UUID in the format used by ACPI, with a BUFFER_OP prefix.
365 *
366 * @ctx: ACPI context pointer
367 * @uuid: UUID to write in the form aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
368 * @return 0 if OK, -EINVAL if the format is incorrect
369 */
370int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid);
371
Simon Glass9c70e7e2020-07-07 13:11:59 -0600372/**
373 * acpigen_emit_ext_op() - Emit an extended op with the EXT_OP_PREFIX prefix
374 *
375 * @ctx: ACPI context pointer
376 * @op: Operation code (e.g. SLEEP_OP)
377 */
378void acpigen_emit_ext_op(struct acpi_ctx *ctx, uint op);
379
380/**
381 * acpigen_write_method() - Write a method header
382 *
383 * @ctx: ACPI context pointer
384 * @name: Method name (4 characters)
385 * @nargs: Number of method arguments (0 if none)
386 */
387void acpigen_write_method(struct acpi_ctx *ctx, const char *name, int nargs);
388
389/**
390 * acpigen_write_method_serialized() - Write a method header
391 *
392 * This sets the 'serialized' flag so that the method is thread-safe
393 *
394 * @ctx: ACPI context pointer
395 * @name: Method name (4 characters)
396 * @nargs: Number of method arguments (0 if none)
397 */
398void acpigen_write_method_serialized(struct acpi_ctx *ctx, const char *name,
399 int nargs);
400
401/**
Simon Glass91c2f9c2020-07-07 21:32:14 -0600402 * acpigen_write_device() - Write an ACPI device
403 *
404 * @ctx: ACPI context pointer
405 * @name: Device name to write
406 */
407void acpigen_write_device(struct acpi_ctx *ctx, const char *name);
408
409/**
Simon Glass9c70e7e2020-07-07 13:11:59 -0600410 * acpigen_write_sta() - Write a _STA method
411 *
412 * @ctx: ACPI context pointer
413 * @status: Status value to return
414 */
415void acpigen_write_sta(struct acpi_ctx *ctx, uint status);
416
417/**
Simon Glassd7d631d2020-07-07 21:32:11 -0600418 * acpigen_write_resourcetemplate_header() - Write a ResourceTemplate header
419 *
420 * @ctx: ACPI context pointer
421 */
422void acpigen_write_resourcetemplate_header(struct acpi_ctx *ctx);
423
424/**
425 * acpigen_write_resourcetemplate_footer() - Write a ResourceTemplate footer
426 *
427 * @ctx: ACPI context pointer
428 */
429void acpigen_write_resourcetemplate_footer(struct acpi_ctx *ctx);
430
431/**
432 * acpigen_write_register_resource() - Write a register resource
433 *
434 * This writes a header, the address information and a footer
435 *
436 * @ctx: ACPI context pointer
437 * @addr: Address to write
438 */
439void acpigen_write_register_resource(struct acpi_ctx *ctx,
440 const struct acpi_gen_regaddr *addr);
441
442/**
Simon Glass9c70e7e2020-07-07 13:11:59 -0600443 * acpigen_write_sleep() - Write a sleep operation
444 *
445 * @ctx: ACPI context pointer
446 * @sleep_ms: Number of milliseconds to sleep for
447 */
448void acpigen_write_sleep(struct acpi_ctx *ctx, u64 sleep_ms);
449
450/**
451 * acpigen_write_store() - Write a store operation
452 *
453 * @ctx: ACPI context pointer
454 */
455void acpigen_write_store(struct acpi_ctx *ctx);
456
457/**
458 * acpigen_write_debug_string() - Write a debug string
459 *
460 * This writes a debug operation with an associated string
461 *
462 * @ctx: ACPI context pointer
463 * @str: String to write
464 */
465void acpigen_write_debug_string(struct acpi_ctx *ctx, const char *str);
466
467/**
468 * acpigen_write_or() - Write a bitwise OR operation
469 *
470 * res = arg1 | arg2
471 *
472 * @ctx: ACPI context pointer
473 * @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP)
474 * @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP)
475 * @res: ACPI opcode for result (e.g. LOCAL2_OP)
476 */
477void acpigen_write_or(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res);
478
479/**
480 * acpigen_write_and() - Write a bitwise AND operation
481 *
482 * res = arg1 & arg2
483 *
484 * @ctx: ACPI context pointer
485 * @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP)
486 * @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP)
487 * @res: ACPI opcode for result (e.g. LOCAL2_OP)
488 */
489void acpigen_write_and(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res);
490
491/**
492 * acpigen_write_not() - Write a bitwise NOT operation
493 *
494 * res = ~arg1
495 *
496 * @ctx: ACPI context pointer
497 * @arg: ACPI opcode for operand (e.g. LOCAL0_OP)
498 * @res: ACPI opcode for result (e.g. LOCAL2_OP)
499 */
500void acpigen_write_not(struct acpi_ctx *ctx, u8 arg, u8 res);
501
Simon Glassf9189d52020-07-07 13:12:00 -0600502/**
503 * acpigen_write_power_res() - Write a power resource
504 *
505 * Name (_PRx, Package(One) { name })
506 * ...
507 * PowerResource (name, level, order)
508 *
509 * The caller should fill in the rest of the power resource and then call
510 * acpigen_pop_len() to close it off
511 *
512 * @ctx: ACPI context pointer
513 * @name: Name of power resource (e.g. "PRIC")
514 * @level: Deepest sleep level that this resource must be kept on (0=S0, 3=S3)
515 * @order: Order that this must be enabled/disabled (e.g. 0)
516 * @dev_stats: List of states to define, e.g. {"_PR0", "_PR3"}
517 * @dev_states_count: Number of dev states
518 */
519void acpigen_write_power_res(struct acpi_ctx *ctx, const char *name, uint level,
520 uint order, const char *const dev_states[],
521 size_t dev_states_count);
522
Simon Glassf8054dd2020-07-07 13:12:01 -0600523/**
524 * acpigen_set_enable_tx_gpio() - Emit ACPI code to enable/disable a GPIO
525 *
526 * This emits code to either enable to disable a Tx GPIO. It takes account of
527 * the GPIO polarity.
528 *
529 * The code needs access to the DW0 register for the pad being used. This is
530 * provided by gpio->pin0_addr and ACPI methods must be defined for the board
531 * which can read and write the pad's DW0 register given this address:
532 * @dw0_read: takes a single argument, the DW0 address
533 * returns the DW0 value
534 * @dw0:write: takes two arguments, the DW0 address and the value to write
535 * no return value
536 *
537 * Example code (-- means comment):
538 *
539 * -- Get Pad Configuration DW0 register value
540 * Method (GPC0, 0x1, Serialized)
541 * {
542 * -- Arg0 - GPIO DW0 address
543 * Store (Arg0, Local0)
544 * OperationRegion (PDW0, SystemMemory, Local0, 4)
545 * Field (PDW0, AnyAcc, NoLock, Preserve) {
546 * TEMP, 32
547 * }
548 * Return (TEMP)
549 * }
550 *
551 * -- Set Pad Configuration DW0 register value
552 * Method (SPC0, 0x2, Serialized)
553 * {
554 * -- Arg0 - GPIO DW0 address
555 * -- Arg1 - Value for DW0 register
556 * Store (Arg0, Local0)
557 * OperationRegion (PDW0, SystemMemory, Local0, 4)
558 * Field (PDW0, AnyAcc, NoLock, Preserve) {
559 * TEMP,32
560 * }
561 * Store (Arg1, TEMP)
562 * }
563 *
564 *
565 * @ctx: ACPI context pointer
566 * @tx_state_val: Mask to use to toggle the TX state on the GPIO pin, e,g.
567 * PAD_CFG0_TX_STATE
568 * @dw0_read: Method name to use to read dw0, e.g. "\\_SB.GPC0"
569 * @dw0_write: Method name to use to read dw0, e.g. "\\_SB.SPC0"
570 * @gpio: GPIO to change
571 * @enable: true to enable GPIO, false to disable
572 * Returns 0 on success, -ve on error.
573 */
574int acpigen_set_enable_tx_gpio(struct acpi_ctx *ctx, u32 tx_state_val,
575 const char *dw0_read, const char *dw0_write,
576 struct acpi_gpio *gpio, bool enable);
577
Simon Glasse0a896b2020-09-22 12:44:56 -0600578/**
579 * acpigen_write_prw() - Write a power resource for wake (_PRW)
580 *
581 * @ctx: ACPI context pointer
582 * @wake: GPE that wakes up the device
583 * @level: Deepest power system sleeping state that can be entered while still
584 * providing wake functionality
585 */
586void acpigen_write_prw(struct acpi_ctx *ctx, uint wake, uint level);
587
Simon Glassda7cff32020-09-22 12:44:57 -0600588/**
589 * acpigen_write_if() - Write an If block
590 *
591 * This requires a call to acpigen_pop_len() to complete the block
592 *
593 * @ctx: ACPI context pointer
594 */
595void acpigen_write_if(struct acpi_ctx *ctx);
596
597/**
598 * acpigen_write_if_lequal_op_int() - Write comparison between op and integer
599 *
600 * Generates ACPI code for checking if operand1 and operand2 are equal
601 *
602 * If (Lequal (op, val))
603 *
604 * @ctx: ACPI context pointer
605 * @op: Operand to check
606 * @val: Value to check against
607 */
608void acpigen_write_if_lequal_op_int(struct acpi_ctx *ctx, uint op, u64 val);
609
610/**
611 * acpigen_write_else() - Write an Ef block
612 *
613 * This requires a call to acpigen_pop_len() to complete the block
614 *
615 * @ctx: ACPI context pointer
616 */
617void acpigen_write_else(struct acpi_ctx *ctx);
618
619/**
620 * acpigen_write_to_buffer() - Write a ToBuffer operation
621 *
622 * E.g.: to generate: ToBuffer (Arg0, Local0)
623 * use acpigen_write_to_buffer(ctx, ARG0_OP, LOCAL0_OP)
624 *
625 * @ctx: ACPI context pointer
626 * @src: Source argument
627 * @dst: Destination argument
628 */
629void acpigen_write_to_buffer(struct acpi_ctx *ctx, uint src, uint dst);
630
631/**
632 * acpigen_write_to_integer() - Write a ToInteger operation
633 *
634 * E.g.: to generate: ToInteger (Arg0, Local0)
635 * use acpigen_write_to_integer(ctx, ARG0_OP, LOCAL0_OP)
636 *
637 * @ctx: ACPI context pointer
638 * @src: Source argument
639 * @dst: Destination argument
640 */
641void acpigen_write_to_integer(struct acpi_ctx *ctx, uint src, uint dst);
642
643/**
644 * acpigen_write_return_byte_buffer() - Write a return of a byte buffer
645 *
646 * @ctx: ACPI context pointer
647 * @arr: Array of bytes to return
648 * @size: Number of bytes
649 */
650void acpigen_write_return_byte_buffer(struct acpi_ctx *ctx, u8 *arr,
651 size_t size);
652
653/**
654 * acpigen_write_return_singleton_buffer() - Write a return of a 1-byte buffer
655 *
656 * @ctx: ACPI context pointer
657 * @arg: Byte to return
658 */
659void acpigen_write_return_singleton_buffer(struct acpi_ctx *ctx, uint arg);
660
661/**
662 * acpigen_write_return_byte() - Write a return of a byte
663 *
664 * @ctx: ACPI context pointer
665 * @arg: Byte to return
666 */
667void acpigen_write_return_byte(struct acpi_ctx *ctx, uint arg);
668
Simon Glass88490e12020-09-22 12:44:58 -0600669/**
670 * acpigen_write_dsm_start() - Start a _DSM method
671 *
672 * Generate ACPI AML code to start the _DSM method.
673 *
674 * The functions need to be called in the correct sequence as below.
675 *
676 * Within the <generate-code-here> region, Local0 and Local1 must be are left
677 * untouched, but Local2-Local7 can be used
678 *
679 * Arguments passed into _DSM method:
680 * Arg0 = UUID
681 * Arg1 = Revision
682 * Arg2 = Function index
683 * Arg3 = Function-specific arguments
684 *
685 * AML code generated looks like this:
686 * Method (_DSM, 4, Serialized) { -- acpigen_write_dsm_start)
687 * ToBuffer (Arg0, Local0)
688 * If (LEqual (Local0, ToUUID(uuid))) { -- acpigen_write_dsm_uuid_start
689 * ToInteger (Arg2, Local1)
690 * If (LEqual (Local1, 0)) { -- acpigen_write_dsm_uuid_start_cond
691 * <generate-code-here>
692 * } -- acpigen_write_dsm_uuid_end_cond
693 * ...
694 * If (LEqual (Local1, n)) { -- acpigen_write_dsm_uuid_start_cond
695 * <generate-code-here>
696 * } -- acpigen_write_dsm_uuid_end_cond
697 * Return (Buffer (One) { 0x0 })
698 * } -- acpigen_write_dsm_uuid_end
699 * ...
700 * If (LEqual (Local0, ToUUID(uuidn))) {
701 * ...
702 * }
703 * Return (Buffer (One) { 0x0 }) -- acpigen_write_dsm_end
704 * }
705 *
706 * @ctx: ACPI context pointer
707 */
708void acpigen_write_dsm_start(struct acpi_ctx *ctx);
709
710/**
711 * acpigen_write_dsm_uuid_start() - Start a new UUID block
712 *
713 * This starts generation of code to handle a particular UUID:
714 *
715 * If (LEqual (Local0, ToUUID(uuid))) {
716 * ToInteger (Arg2, Local1)
717 *
718 * @ctx: ACPI context pointer
719 */
720int acpigen_write_dsm_uuid_start(struct acpi_ctx *ctx, const char *uuid);
721
722/**
723 * acpigen_write_dsm_uuid_start_cond() - Start a new condition block
724 *
725 * This starts generation of condition-checking code to handle a particular
726 * function:
727 *
728 * If (LEqual (Local1, i))
729 *
730 * @ctx: ACPI context pointer
731 */
732void acpigen_write_dsm_uuid_start_cond(struct acpi_ctx *ctx, int seq);
733
734/**
735 * acpigen_write_dsm_uuid_end_cond() - Start a new condition block
736 *
737 * This ends generation of condition-checking code to handle a particular
738 * function:
739 *
740 * }
741 *
742 * @ctx: ACPI context pointer
743 */
744void acpigen_write_dsm_uuid_end_cond(struct acpi_ctx *ctx);
745
746/**
747 * acpigen_write_dsm_uuid_end() - End a UUID block
748 *
749 * This ends generation of code to handle a particular UUID:
750 *
751 * Return (Buffer (One) { 0x0 })
752 *
753 * @ctx: ACPI context pointer
754 */
755void acpigen_write_dsm_uuid_end(struct acpi_ctx *ctx);
756
757/**
758 * acpigen_write_dsm_end() - End a _DSM method
759 *
760 * This ends generates of the _DSM block:
761 *
762 * Return (Buffer (One) { 0x0 })
763 *
764 * @ctx: ACPI context pointer
765 */
766void acpigen_write_dsm_end(struct acpi_ctx *ctx);
767
Simon Glass61cc9332020-07-07 13:11:42 -0600768#endif