blob: c1a6bc263caec9ad34c7f75dee5324c8429d877a [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;
16
Simon Glass7e148f22020-07-07 13:11:50 -060017/* Top 4 bits of the value used to indicate a three-byte length value */
18#define ACPI_PKG_LEN_3_BYTES 0x80
19
Simon Glass03967ce2020-07-07 13:11:51 -060020/* ACPI Op/Prefix codes */
21enum {
22 PACKAGE_OP = 0x12,
23};
24
Simon Glass61cc9332020-07-07 13:11:42 -060025/**
26 * acpigen_get_current() - Get the current ACPI code output pointer
27 *
28 * @ctx: ACPI context pointer
29 * @return output pointer
30 */
31u8 *acpigen_get_current(struct acpi_ctx *ctx);
32
33/**
34 * acpigen_emit_byte() - Emit a byte to the ACPI code
35 *
36 * @ctx: ACPI context pointer
37 * @data: Value to output
38 */
39void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
40
41/**
42 * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
43 *
44 * @ctx: ACPI context pointer
45 * @data: Value to output
46 */
47void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
48
49/**
50 * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
51 *
52 * @ctx: ACPI context pointer
53 * @data: Value to output
54 */
55void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
56
Simon Glass7fb8da42020-07-07 13:11:45 -060057/**
58 * acpigen_emit_stream() - Emit a stream of bytes
59 *
60 * @ctx: ACPI context pointer
61 * @data: Data to output
62 * @size: Size of data in bytes
63 */
64void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
65
66/**
67 * acpigen_emit_string() - Emit a string
68 *
69 * Emit a string with a null terminator
70 *
71 * @ctx: ACPI context pointer
72 * @str: String to output, or NULL for an empty string
73 */
74void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
75
Simon Glass7e148f22020-07-07 13:11:50 -060076/**
77 * acpigen_write_len_f() - Write a 'forward' length placeholder
78 *
79 * This adds space for a length value in the ACPI stream and pushes the current
80 * position (before the length) on the stack. After calling this you can write
81 * some data and then call acpigen_pop_len() to update the length value.
82 *
83 * Usage:
84 *
85 * acpigen_write_len_f() ------\
86 * acpigen_write...() |
87 * acpigen_write...() |
88 * acpigen_write_len_f() --\ |
89 * acpigen_write...() | |
90 * acpigen_write...() | |
91 * acpigen_pop_len() ------/ |
92 * acpigen_write...() |
93 * acpigen_pop_len() ----------/
94 *
95 * See ACPI 6.3 section 20.2.4 Package Length Encoding
96 *
97 * This implementation always uses a 3-byte packet length for simplicity. It
98 * could be adjusted to support other lengths.
99 *
100 * @ctx: ACPI context pointer
101 */
102void acpigen_write_len_f(struct acpi_ctx *ctx);
103
104/**
105 * acpigen_pop_len() - Update the previously stacked length placeholder
106 *
107 * Call this after the data for the block has been written. It updates the
108 * top length value in the stack and pops it off.
109 *
110 * @ctx: ACPI context pointer
111 */
112void acpigen_pop_len(struct acpi_ctx *ctx);
113
Simon Glass03967ce2020-07-07 13:11:51 -0600114/**
115 * acpigen_write_package() - Start writing a package
116 *
117 * A package collects together a number of elements in the ACPI code. To write
118 * a package use:
119 *
120 * acpigen_write_package(ctx, 3);
121 * ...write things
122 * acpigen_pop_len()
123 *
124 * If you don't know the number of elements in advance, acpigen_write_package()
125 * returns a pointer to the value so you can update it later:
126 *
127 * char *num_elements = acpigen_write_package(ctx, 0);
128 * ...write things
129 * *num_elements += 1;
130 * ...write things
131 * *num_elements += 1;
132 * acpigen_pop_len()
133 *
134 * @ctx: ACPI context pointer
135 * @nr_el: Number of elements (0 if not known)
136 * @returns pointer to the number of elements, which can be updated by the
137 * caller if needed
138 */
139char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
140
Simon Glass61cc9332020-07-07 13:11:42 -0600141#endif