xref: /freebsd/usr.sbin/bhyve/basl.h (revision d0f168e680ff22699c98008d75664a6f8c431b7e)
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 int basl_finish(void);
44 int basl_init(void);
45 int basl_table_append_bytes(struct basl_table *table, const void *bytes,
46     uint32_t len);
47 int basl_table_append_checksum(struct basl_table *table, uint32_t start,
48     uint32_t len);
49 int basl_table_append_gas(struct basl_table *table, uint8_t space_id,
50     uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
51     uint64_t address);
52 int basl_table_append_header(struct basl_table *table,
53     const uint8_t signature[ACPI_NAMESEG_SIZE], uint8_t revision,
54     uint32_t oem_revision);
55 int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size);
56 int basl_table_append_length(struct basl_table *table, uint8_t size);
57 int basl_table_append_pointer(struct basl_table *table,
58     const uint8_t src_signature[ACPI_NAMESEG_SIZE], uint8_t size);
59 int basl_table_create(struct basl_table **table, struct vmctx *ctx,
60     const uint8_t *name, uint32_t alignment, uint32_t off);
61