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