2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
5 * Author: Corvin Köhne <c.koehne@beckhoff.com>
10 #include "qemu_fwcfg.h"
15 * Some guest bios like seabios assume the RSDP to be located in the FSEG. Bhyve
16 * only supports OVMF which has no such requirement.
18 enum qemu_loader_zone {
19 QEMU_LOADER_ALLOC_HIGH = 1,
20 QEMU_LOADER_ALLOC_FSEG, /* 0x0F000000 - 0x100000 */
24 * Loads a fwcfg item into guest memory. This command has to be issued before
25 * any subsequent command can be used.
27 * @param loader Qemu loader instance the command should be added to.
28 * @param name Name of the fwcfg item which should be allocated.
29 * @param alignment Alignment required by the data.
30 * @param zone Memory zone in which it should be loaded.
32 int qemu_loader_alloc(struct qemu_loader *loader, const uint8_t *name,
33 uint32_t alignment, enum qemu_loader_zone zone);
35 * Calculates a checksum for @p name and writes it to @p name + @p off . The
36 * checksum calculation ranges from @p start to @p start + @p len. The checksum
37 * field is always one byte large and all bytes in the specified range,
38 * including the checksum, have to sum up to 0.
40 * @param loader Qemu loader instance the command should be added to.
41 * @param name Name of the fwcfg item which should be patched.
42 * @param off Offset into @p name .
43 * @param start Start offset of checksum calculation.
44 * @param len Length of the checksum calculation.
46 int qemu_loader_add_checksum(struct qemu_loader *loader, const uint8_t *name,
47 uint32_t off, uint32_t start, uint32_t len);
49 * Adds the address of @p src_name to the value at @p dest_name + @p off . The
50 * size of the pointer is determined by @p dest_size and should be 1, 2, 4 or 8.
52 * @param loader Qemu loader instance the command should be added to.
53 * @param dest_name Name of the fwcfg item which should be patched.
54 * @param src_name Name of the fwcfg item which address should be written to
55 * @p dest_name + @p off.
56 * @param off Offset into @p dest_name .
57 * @param size Size of the pointer (1, 2, 4 or 8).
59 int qemu_loader_add_pointer(struct qemu_loader *loader,
60 const uint8_t *dest_name, const uint8_t *src_name, uint32_t off,
64 * Creates a qemu loader instance.
66 * @param new_loader Returns the newly created qemu loader instance.
67 * @param fwcfg_name Name of the FwCfg item which represents the qemu loader
69 int qemu_loader_create(struct qemu_loader **new_loader,
70 const uint8_t *fwcfg_name);
72 * Signals that all commands are written to the qemu loader. This function
73 * creates a proper FwCfg item and registers it.
75 * @param loader Qemu loader instance which should be finished.
77 int qemu_loader_finish(struct qemu_loader *loader);