xref: /freebsd/usr.sbin/bhyve/basl.h (revision 7543a9c0280a0f4262489671936a6e03b9b2c563)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
5  */
6 
7 #pragma once
8 
9 #pragma clang diagnostic push
10 #pragma clang diagnostic ignored "-Wunused-parameter"
11 #include <contrib/dev/acpica/include/acpi.h>
12 #pragma clang diagnostic pop
13 
14 #define ACPI_GAS_ACCESS_WIDTH_LEGACY 0
15 #define ACPI_GAS_ACCESS_WIDTH_UNDEFINED 0
16 #define ACPI_GAS_ACCESS_WIDTH_BYTE 1
17 #define ACPI_GAS_ACCESS_WIDTH_WORD 2
18 #define ACPI_GAS_ACCESS_WIDTH_DWORD 3
19 #define ACPI_GAS_ACCESS_WIDTH_QWORD 4
20 
21 #define BHYVE_ACPI_BASE 0xf2400
22 
23 #define BASL_TABLE_ALIGNMENT 0x10
24 #define BASL_TABLE_ALIGNMENT_FACS 0x40
25 
26 #define BASL_TABLE_CHECKSUM_LEN_FULL_TABLE (-1U)
27 
28 #define BASL_EXEC(x)                                                         \
29 	do {                                                                 \
30 		const int error = (x);                                       \
31 		if (error) {                                                 \
32 			warnc(error,                                         \
33 			    "BASL failed @ %s:%d\n    Failed to execute %s", \
34 			    __func__, __LINE__, #x);                         \
35 			return (error);                                      \
36 		}                                                            \
37 	} while (0)
38 
39 #define QEMU_FWCFG_MAX_NAME 56
40 
41 struct basl_table;
42 
43 void basl_fill_gas(ACPI_GENERIC_ADDRESS *gas, uint8_t space_id,
44     uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
45     uint64_t address);
46 int basl_finish(void);
47 int basl_init(void);
48 int basl_table_add_checksum(struct basl_table *const table, const uint32_t off,
49     const uint32_t start, const uint32_t len);
50 int basl_table_add_length(struct basl_table *const table, const uint32_t off,
51     const uint8_t size);
52 int basl_table_add_pointer(struct basl_table *const table,
53     const uint8_t src_signature[ACPI_NAMESEG_SIZE], const uint32_t off,
54     const uint8_t size);
55 int basl_table_append_bytes(struct basl_table *table, const void *bytes,
56     uint32_t len);
57 int basl_table_append_checksum(struct basl_table *table, uint32_t start,
58     uint32_t len);
59 /* Add an ACPI_TABLE_* to basl without its header. */
60 int basl_table_append_content(struct basl_table *table, void *data,
61     uint32_t len);
62 int basl_table_append_gas(struct basl_table *table, uint8_t space_id,
63     uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
64     uint64_t address);
65 int basl_table_append_header(struct basl_table *table,
66     const uint8_t signature[ACPI_NAMESEG_SIZE], uint8_t revision,
67     uint32_t oem_revision);
68 int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size);
69 int basl_table_append_length(struct basl_table *table, uint8_t size);
70 int basl_table_append_pointer(struct basl_table *table,
71     const uint8_t src_signature[ACPI_NAMESEG_SIZE], uint8_t size);
72 int basl_table_create(struct basl_table **table, struct vmctx *ctx,
73     const uint8_t *name, uint32_t alignment);
74