xref: /illumos-gate/usr/src/cmd/bhyve/common/basl.h (revision 5c4a5fe16715fb423db76577a6883b5bbecdbe45)
1*5c4a5fe1SAndy Fiddaman /*-
2*5c4a5fe1SAndy Fiddaman  * SPDX-License-Identifier: BSD-2-Clause
3*5c4a5fe1SAndy Fiddaman  *
4*5c4a5fe1SAndy Fiddaman  * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
5*5c4a5fe1SAndy Fiddaman  */
6*5c4a5fe1SAndy Fiddaman 
7*5c4a5fe1SAndy Fiddaman #pragma once
8*5c4a5fe1SAndy Fiddaman 
9*5c4a5fe1SAndy Fiddaman #pragma GCC diagnostic push
10*5c4a5fe1SAndy Fiddaman #pragma GCC diagnostic ignored "-Wunused-parameter"
11*5c4a5fe1SAndy Fiddaman #include <contrib/dev/acpica/include/acpi.h>
12*5c4a5fe1SAndy Fiddaman #pragma GCC diagnostic pop
13*5c4a5fe1SAndy Fiddaman 
14*5c4a5fe1SAndy Fiddaman #ifndef	__FreeBSD__
15*5c4a5fe1SAndy Fiddaman /* Until the in-gate ACPI is updated, map the new name to the old. */
16*5c4a5fe1SAndy Fiddaman #define	ACPI_NAMESEG_SIZE	ACPI_NAME_SIZE
17*5c4a5fe1SAndy Fiddaman /*
18*5c4a5fe1SAndy Fiddaman  * Also to avoid type conflicts without having to pepper the code with ifdefs,
19*5c4a5fe1SAndy Fiddaman  * redefine these constants to be uint8_t *
20*5c4a5fe1SAndy Fiddaman  */
21*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_FACS
22*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_MCFG
23*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_HPET
24*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_MADT
25*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_DSDT
26*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_FADT
27*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_XSDT
28*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_RSDT
29*5c4a5fe1SAndy Fiddaman #undef ACPI_RSDP_NAME
30*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_SPCR
31*5c4a5fe1SAndy Fiddaman #undef ACPI_SIG_TPM2
32*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_FACS           (const uint8_t *)"FACS"
33*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_MCFG		(const uint8_t *)"MCFG"
34*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_HPET		(const uint8_t *)"HPET"
35*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_MADT		(const uint8_t *)"APIC"
36*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_DSDT		(const uint8_t *)"DSDT"
37*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_FADT		(const uint8_t *)"FACP"
38*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_XSDT		(const uint8_t *)"XSDT"
39*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_RSDT		(const uint8_t *)"RSDT"
40*5c4a5fe1SAndy Fiddaman #define	ACPI_RSDP_NAME		(const uint8_t *)"RSDP"
41*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_SPCR		(const uint8_t *)"SPCR"
42*5c4a5fe1SAndy Fiddaman #define	ACPI_SIG_TPM2		(const uint8_t *)"TPM2"
43*5c4a5fe1SAndy Fiddaman #endif /* !__FreeBSD__ */
44*5c4a5fe1SAndy Fiddaman 
45*5c4a5fe1SAndy Fiddaman #include "qemu_fwcfg.h"
46*5c4a5fe1SAndy Fiddaman 
47*5c4a5fe1SAndy Fiddaman #define ACPI_GAS_ACCESS_WIDTH_LEGACY 0
48*5c4a5fe1SAndy Fiddaman #define ACPI_GAS_ACCESS_WIDTH_UNDEFINED 0
49*5c4a5fe1SAndy Fiddaman #define ACPI_GAS_ACCESS_WIDTH_BYTE 1
50*5c4a5fe1SAndy Fiddaman #define ACPI_GAS_ACCESS_WIDTH_WORD 2
51*5c4a5fe1SAndy Fiddaman #define ACPI_GAS_ACCESS_WIDTH_DWORD 3
52*5c4a5fe1SAndy Fiddaman #define ACPI_GAS_ACCESS_WIDTH_QWORD 4
53*5c4a5fe1SAndy Fiddaman 
54*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_INTERRUPT_TYPE_8259 0x1
55*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_INTERRUPT_TYPE_APIC 0x2
56*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_INTERRUPT_TYPE_SAPIC 0x4
57*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_INTERRUPT_TYPE_GIC 0x8
58*5c4a5fe1SAndy Fiddaman 
59*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_BAUD_RATE_9600 3
60*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_BAUD_RATE_19200 4
61*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_BAUD_RATE_57600 6
62*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_BAUD_RATE_115200 7
63*5c4a5fe1SAndy Fiddaman 
64*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_PARITY_NO_PARITY 0
65*5c4a5fe1SAndy Fiddaman 
66*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_STOP_BITS_1 1
67*5c4a5fe1SAndy Fiddaman 
68*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_FLOW_CONTROL_DCD 0x1
69*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_FLOW_CONTROL_RTS_CTS 0x2
70*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_FLOW_CONTROL_XON_XOFF 0x4
71*5c4a5fe1SAndy Fiddaman 
72*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_TERMINAL_TYPE_VT100 0
73*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_TERMINAL_TYPE_VT100_PLUS 1
74*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_TERMINAL_TYPE_VT_UTF8 2
75*5c4a5fe1SAndy Fiddaman #define ACPI_SPCR_TERMINAL_TYPE_ANSI 3
76*5c4a5fe1SAndy Fiddaman 
77*5c4a5fe1SAndy Fiddaman #define BHYVE_ACPI_BASE 0xf2400
78*5c4a5fe1SAndy Fiddaman 
79*5c4a5fe1SAndy Fiddaman #define BASL_TABLE_ALIGNMENT 0x10
80*5c4a5fe1SAndy Fiddaman #define BASL_TABLE_ALIGNMENT_FACS 0x40
81*5c4a5fe1SAndy Fiddaman 
82*5c4a5fe1SAndy Fiddaman #define BASL_TABLE_CHECKSUM_LEN_FULL_TABLE (-1U)
83*5c4a5fe1SAndy Fiddaman 
84*5c4a5fe1SAndy Fiddaman #define BASL_EXEC(x)                                                         \
85*5c4a5fe1SAndy Fiddaman 	do {                                                                 \
86*5c4a5fe1SAndy Fiddaman 		const int error = (x);                                       \
87*5c4a5fe1SAndy Fiddaman 		if (error) {                                                 \
88*5c4a5fe1SAndy Fiddaman 			warnc(error,                                         \
89*5c4a5fe1SAndy Fiddaman 			    "BASL failed @ %s:%d\n    Failed to execute %s", \
90*5c4a5fe1SAndy Fiddaman 			    __func__, __LINE__, #x);                         \
91*5c4a5fe1SAndy Fiddaman 			return (error);                                      \
92*5c4a5fe1SAndy Fiddaman 		}                                                            \
93*5c4a5fe1SAndy Fiddaman 	} while (0)
94*5c4a5fe1SAndy Fiddaman 
95*5c4a5fe1SAndy Fiddaman struct basl_table;
96*5c4a5fe1SAndy Fiddaman 
97*5c4a5fe1SAndy Fiddaman void basl_fill_gas(ACPI_GENERIC_ADDRESS *gas, uint8_t space_id,
98*5c4a5fe1SAndy Fiddaman     uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
99*5c4a5fe1SAndy Fiddaman     uint64_t address);
100*5c4a5fe1SAndy Fiddaman int basl_finish(void);
101*5c4a5fe1SAndy Fiddaman int basl_init(struct vmctx *ctx);
102*5c4a5fe1SAndy Fiddaman int basl_table_add_checksum(struct basl_table *const table, const uint32_t off,
103*5c4a5fe1SAndy Fiddaman     const uint32_t start, const uint32_t len);
104*5c4a5fe1SAndy Fiddaman int basl_table_add_length(struct basl_table *const table, const uint32_t off,
105*5c4a5fe1SAndy Fiddaman     const uint8_t size);
106*5c4a5fe1SAndy Fiddaman int basl_table_add_pointer(struct basl_table *const table,
107*5c4a5fe1SAndy Fiddaman     const uint8_t src_signature[ACPI_NAMESEG_SIZE], const uint32_t off,
108*5c4a5fe1SAndy Fiddaman     const uint8_t size);
109*5c4a5fe1SAndy Fiddaman int basl_table_append_bytes(struct basl_table *table, const void *bytes,
110*5c4a5fe1SAndy Fiddaman     uint32_t len);
111*5c4a5fe1SAndy Fiddaman int basl_table_append_checksum(struct basl_table *table, uint32_t start,
112*5c4a5fe1SAndy Fiddaman     uint32_t len);
113*5c4a5fe1SAndy Fiddaman /* Add an ACPI_TABLE_* to basl without its header. */
114*5c4a5fe1SAndy Fiddaman int basl_table_append_content(struct basl_table *table, void *data,
115*5c4a5fe1SAndy Fiddaman     uint32_t len);
116*5c4a5fe1SAndy Fiddaman int basl_table_append_fwcfg(struct basl_table *table,
117*5c4a5fe1SAndy Fiddaman     const uint8_t *fwcfg_name, uint32_t alignment,
118*5c4a5fe1SAndy Fiddaman     uint8_t size);
119*5c4a5fe1SAndy Fiddaman int basl_table_append_gas(struct basl_table *table, uint8_t space_id,
120*5c4a5fe1SAndy Fiddaman     uint8_t bit_width, uint8_t bit_offset, uint8_t access_width,
121*5c4a5fe1SAndy Fiddaman     uint64_t address);
122*5c4a5fe1SAndy Fiddaman int basl_table_append_header(struct basl_table *table,
123*5c4a5fe1SAndy Fiddaman     const uint8_t signature[ACPI_NAMESEG_SIZE], uint8_t revision,
124*5c4a5fe1SAndy Fiddaman     uint32_t oem_revision);
125*5c4a5fe1SAndy Fiddaman int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size);
126*5c4a5fe1SAndy Fiddaman int basl_table_append_length(struct basl_table *table, uint8_t size);
127*5c4a5fe1SAndy Fiddaman int basl_table_append_pointer(struct basl_table *table,
128*5c4a5fe1SAndy Fiddaman     const uint8_t src_signature[ACPI_NAMESEG_SIZE], uint8_t size);
129*5c4a5fe1SAndy Fiddaman int basl_table_create(struct basl_table **table, struct vmctx *ctx,
130*5c4a5fe1SAndy Fiddaman     const uint8_t *name, uint32_t alignment);
131*5c4a5fe1SAndy Fiddaman /* Adds the table to RSDT and XSDT */
132*5c4a5fe1SAndy Fiddaman int basl_table_register_to_rsdt(struct basl_table *table);
133