blob: 671f1d0eea8a2791cf77fdb4c8266990d0b7f29a [file] [log] [blame]
Simon Glass98528d42020-07-07 13:11:42 -06001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Generation of ACPI (Advanced Configuration and Power Interface) tables
4 *
5 * Copyright 2019 Google LLC
6 * Mostly taken from coreboot
7 */
8
9#define LOG_CATEGORY LOGC_ACPI
10
11#include <common.h>
12#include <dm.h>
13#include <acpi/acpigen.h>
14#include <dm/acpi.h>
15
16u8 *acpigen_get_current(struct acpi_ctx *ctx)
17{
18 return ctx->current;
19}
20
21void acpigen_emit_byte(struct acpi_ctx *ctx, uint data)
22{
23 *(u8 *)ctx->current++ = data;
24}
25
26void acpigen_emit_word(struct acpi_ctx *ctx, uint data)
27{
28 acpigen_emit_byte(ctx, data & 0xff);
29 acpigen_emit_byte(ctx, (data >> 8) & 0xff);
30}
31
32void acpigen_emit_dword(struct acpi_ctx *ctx, uint data)
33{
34 /* Output the value in little-endian format */
35 acpigen_emit_byte(ctx, data & 0xff);
36 acpigen_emit_byte(ctx, (data >> 8) & 0xff);
37 acpigen_emit_byte(ctx, (data >> 16) & 0xff);
38 acpigen_emit_byte(ctx, (data >> 24) & 0xff);
39}
Simon Glass071c4a52020-07-07 13:11:45 -060040
41void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size)
42{
43 int i;
44
45 for (i = 0; i < size; i++)
46 acpigen_emit_byte(ctx, data[i]);
47}
48
49void acpigen_emit_string(struct acpi_ctx *ctx, const char *str)
50{
51 acpigen_emit_stream(ctx, str, str ? strlen(str) : 0);
52 acpigen_emit_byte(ctx, '\0');
53}