xref: /freebsd/usr.sbin/bhyve/basl.h (revision 2e3f49888ec8851bafb22011533217487764fdb0)
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 GCC diagnostic push
10 #pragma GCC diagnostic ignored "-Wunused-parameter"
11 #include <contrib/dev/acpica/include/acpi.h>
12 #pragma GCC diagnostic pop
13 
14 #include "qemu_fwcfg.h"
15 
16 #define ACPI_GAS_ACCESS_WIDTH_LEGACY 0
17 #define ACPI_GAS_ACCESS_WIDTH_UNDEFINED 0
18 #define ACPI_GAS_ACCESS_WIDTH_BYTE 1
19 #define ACPI_GAS_ACCESS_WIDTH_WORD 2
20 #define ACPI_GAS_ACCESS_WIDTH_DWORD 3
21 #define ACPI_GAS_ACCESS_WIDTH_QWORD 4
22 
23 #define ACPI_SPCR_INTERRUPT_TYPE_8259 0x1
24 #define ACPI_SPCR_INTERRUPT_TYPE_APIC 0x2
25 #define ACPI_SPCR_INTERRUPT_TYPE_SAPIC 0x4
26 #define ACPI_SPCR_INTERRUPT_TYPE_GIC 0x8
27 
28 #define ACPI_SPCR_BAUD_RATE_9600 3
29 #define ACPI_SPCR_BAUD_RATE_19200 4
30 #define ACPI_SPCR_BAUD_RATE_57600 6
31 #define ACPI_SPCR_BAUD_RATE_115200 7
32 
33 #define ACPI_SPCR_PARITY_NO_PARITY 0
34 
35 #define ACPI_SPCR_STOP_BITS_1 1
36 
37 #define ACPI_SPCR_FLOW_CONTROL_DCD 0x1
38 #define ACPI_SPCR_FLOW_CONTROL_RTS_CTS 0x2
39 #define ACPI_SPCR_FLOW_CONTROL_XON_XOFF 0x4
40 
41 #define ACPI_SPCR_TERMINAL_TYPE_VT100 0
42 #define ACPI_SPCR_TERMINAL_TYPE_VT100_PLUS 1
43 #define ACPI_SPCR_TERMINAL_TYPE_VT_UTF8 2
44 #define ACPI_SPCR_TERMINAL_TYPE_ANSI 3
45 
46 #define BHYVE_ACPI_BASE 0xf2400
47 
48 #define BASL_TABLE_ALIGNMENT 0x10
49 #define BASL_TABLE_ALIGNMENT_FACS 0x40
50 
51 #define BASL_TABLE_CHECKSUM_LEN_FULL_TABLE (-1U)
52 
53 #define BASL_EXEC(x)                                                         \
54 	do {                                                                 \
55 		const int error = (x);                                       \
56 		if (error) {                                                 \
57 			warnc(error,                                         \
58 			    "BASL failed @ %s:%d\n    Failed to execute %s", \
59 			    __func__, __LINE__, #x);                         \
60 			return (error);                                      \
61 		}                                                            \
62 	} while (0)
63 
64 struct basl_table;
65 
66 void basl_fill_gas(ACPI_GENERIC_ADDRESS *gas, uint8_t space_id,
67     uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
68     uint64_t address);
69 int basl_finish(void);
70 int basl_init(struct vmctx *ctx);
71 int basl_table_add_checksum(struct basl_table *const table, const uint32_t off,
72     const uint32_t start, const uint32_t len);
73 int basl_table_add_length(struct basl_table *const table, const uint32_t off,
74     const uint8_t size);
75 int basl_table_add_pointer(struct basl_table *const table,
76     const uint8_t src_signature[ACPI_NAMESEG_SIZE], const uint32_t off,
77     const uint8_t size);
78 int basl_table_append_bytes(struct basl_table *table, const void *bytes,
79     uint32_t len);
80 int basl_table_append_checksum(struct basl_table *table, uint32_t start,
81     uint32_t len);
82 /* Add an ACPI_TABLE_* to basl without its header. */
83 int basl_table_append_content(struct basl_table *table, void *data,
84     uint32_t len);
85 int basl_table_append_fwcfg(struct basl_table *table,
86     const uint8_t *fwcfg_name, uint32_t alignment,
87     uint8_t size);
88 int basl_table_append_gas(struct basl_table *table, uint8_t space_id,
89     uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
90     uint64_t address);
91 int basl_table_append_header(struct basl_table *table,
92     const uint8_t signature[ACPI_NAMESEG_SIZE], uint8_t revision,
93     uint32_t oem_revision);
94 int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size);
95 int basl_table_append_length(struct basl_table *table, uint8_t size);
96 int basl_table_append_pointer(struct basl_table *table,
97     const uint8_t src_signature[ACPI_NAMESEG_SIZE], uint8_t size);
98 int basl_table_create(struct basl_table **table, struct vmctx *ctx,
99     const uint8_t *name, uint32_t alignment);
100 /* Adds the table to RSDT and XSDT */
101 int basl_table_register_to_rsdt(struct basl_table *table);
102