121bbc284SCorvin Köhne /*- 221bbc284SCorvin Köhne * SPDX-License-Identifier: BSD-2-Clause 321bbc284SCorvin Köhne * 421bbc284SCorvin Köhne * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG 521bbc284SCorvin Köhne */ 621bbc284SCorvin Köhne 721bbc284SCorvin Köhne #pragma once 821bbc284SCorvin Köhne 90acf6961SJohn Baldwin #pragma GCC diagnostic push 100acf6961SJohn Baldwin #pragma GCC diagnostic ignored "-Wunused-parameter" 1121bbc284SCorvin Köhne #include <contrib/dev/acpica/include/acpi.h> 120acf6961SJohn Baldwin #pragma GCC diagnostic pop 1321bbc284SCorvin Köhne 147959d80dSCorvin Köhne #include "qemu_fwcfg.h" 157959d80dSCorvin Köhne 16995374a6SCorvin Köhne #define ACPI_GAS_ACCESS_WIDTH_LEGACY 0 17995374a6SCorvin Köhne #define ACPI_GAS_ACCESS_WIDTH_UNDEFINED 0 18995374a6SCorvin Köhne #define ACPI_GAS_ACCESS_WIDTH_BYTE 1 19995374a6SCorvin Köhne #define ACPI_GAS_ACCESS_WIDTH_WORD 2 20995374a6SCorvin Köhne #define ACPI_GAS_ACCESS_WIDTH_DWORD 3 21995374a6SCorvin Köhne #define ACPI_GAS_ACCESS_WIDTH_QWORD 4 22995374a6SCorvin Köhne 23b972e7cbSCorvin Köhne #define ACPI_SPCR_INTERRUPT_TYPE_8259 0x1 24b972e7cbSCorvin Köhne #define ACPI_SPCR_INTERRUPT_TYPE_APIC 0x2 25b972e7cbSCorvin Köhne #define ACPI_SPCR_INTERRUPT_TYPE_SAPIC 0x4 26b972e7cbSCorvin Köhne #define ACPI_SPCR_INTERRUPT_TYPE_GIC 0x8 27b972e7cbSCorvin Köhne 28b972e7cbSCorvin Köhne #define ACPI_SPCR_BAUD_RATE_9600 3 29b972e7cbSCorvin Köhne #define ACPI_SPCR_BAUD_RATE_19200 4 30b972e7cbSCorvin Köhne #define ACPI_SPCR_BAUD_RATE_57600 6 31b972e7cbSCorvin Köhne #define ACPI_SPCR_BAUD_RATE_115200 7 32b972e7cbSCorvin Köhne 33b972e7cbSCorvin Köhne #define ACPI_SPCR_PARITY_NO_PARITY 0 34b972e7cbSCorvin Köhne 35b972e7cbSCorvin Köhne #define ACPI_SPCR_STOP_BITS_1 1 36b972e7cbSCorvin Köhne 37b972e7cbSCorvin Köhne #define ACPI_SPCR_FLOW_CONTROL_DCD 0x1 38b972e7cbSCorvin Köhne #define ACPI_SPCR_FLOW_CONTROL_RTS_CTS 0x2 39b972e7cbSCorvin Köhne #define ACPI_SPCR_FLOW_CONTROL_XON_XOFF 0x4 40b972e7cbSCorvin Köhne 41b972e7cbSCorvin Köhne #define ACPI_SPCR_TERMINAL_TYPE_VT100 0 42b972e7cbSCorvin Köhne #define ACPI_SPCR_TERMINAL_TYPE_VT100_PLUS 1 43b972e7cbSCorvin Köhne #define ACPI_SPCR_TERMINAL_TYPE_VT_UTF8 2 44b972e7cbSCorvin Köhne #define ACPI_SPCR_TERMINAL_TYPE_ANSI 3 45b972e7cbSCorvin Köhne 4621bbc284SCorvin Köhne #define BHYVE_ACPI_BASE 0xf2400 4721bbc284SCorvin Köhne 4821bbc284SCorvin Köhne #define BASL_TABLE_ALIGNMENT 0x10 4921bbc284SCorvin Köhne #define BASL_TABLE_ALIGNMENT_FACS 0x40 5021bbc284SCorvin Köhne 51c127c61eSMark Johnston #define BASL_TABLE_CHECKSUM_LEN_FULL_TABLE (-1U) 5229578470SCorvin Köhne 5321bbc284SCorvin Köhne #define BASL_EXEC(x) \ 5421bbc284SCorvin Köhne do { \ 5521bbc284SCorvin Köhne const int error = (x); \ 5621bbc284SCorvin Köhne if (error) { \ 5721bbc284SCorvin Köhne warnc(error, \ 5821bbc284SCorvin Köhne "BASL failed @ %s:%d\n Failed to execute %s", \ 5921bbc284SCorvin Köhne __func__, __LINE__, #x); \ 6021bbc284SCorvin Köhne return (error); \ 6121bbc284SCorvin Köhne } \ 6221bbc284SCorvin Köhne } while (0) 6321bbc284SCorvin Köhne 6421bbc284SCorvin Köhne struct basl_table; 6521bbc284SCorvin Köhne 6660277ad7SCorvin Köhne void basl_fill_gas(ACPI_GENERIC_ADDRESS *gas, uint8_t space_id, 6760277ad7SCorvin Köhne uint8_t bit_width, uint8_t bit_offset, uint8_t access_width, 6860277ad7SCorvin Köhne uint64_t address); 6921bbc284SCorvin Köhne int basl_finish(void); 70*24a0fef9SCorvin Köhne int basl_init(struct vmctx *ctx); 717263419fSCorvin Köhne int basl_table_add_checksum(struct basl_table *const table, const uint32_t off, 727263419fSCorvin Köhne const uint32_t start, const uint32_t len); 737263419fSCorvin Köhne int basl_table_add_length(struct basl_table *const table, const uint32_t off, 747263419fSCorvin Köhne const uint8_t size); 757263419fSCorvin Köhne int basl_table_add_pointer(struct basl_table *const table, 767263419fSCorvin Köhne const uint8_t src_signature[ACPI_NAMESEG_SIZE], const uint32_t off, 777263419fSCorvin Köhne const uint8_t size); 7821bbc284SCorvin Köhne int basl_table_append_bytes(struct basl_table *table, const void *bytes, 7921bbc284SCorvin Köhne uint32_t len); 8029578470SCorvin Köhne int basl_table_append_checksum(struct basl_table *table, uint32_t start, 8129578470SCorvin Köhne uint32_t len); 828897b562SCorvin Köhne /* Add an ACPI_TABLE_* to basl without its header. */ 838897b562SCorvin Köhne int basl_table_append_content(struct basl_table *table, void *data, 848897b562SCorvin Köhne uint32_t len); 854e46ab0eSCorvin Köhne int basl_table_append_fwcfg(struct basl_table *table, 864e46ab0eSCorvin Köhne const uint8_t *fwcfg_name, uint32_t alignment, 874e46ab0eSCorvin Köhne uint8_t size); 88995374a6SCorvin Köhne int basl_table_append_gas(struct basl_table *table, uint8_t space_id, 89995374a6SCorvin Köhne uint8_t bit_width, uint8_t bit_offset, uint8_t access_width, 90995374a6SCorvin Köhne uint64_t address); 912fb0f352SCorvin Köhne int basl_table_append_header(struct basl_table *table, 922fb0f352SCorvin Köhne const uint8_t signature[ACPI_NAMESEG_SIZE], uint8_t revision, 932fb0f352SCorvin Köhne uint32_t oem_revision); 94e22f5ce2SCorvin Köhne int basl_table_append_int(struct basl_table *table, uint64_t val, uint8_t size); 953a766cd0SCorvin Köhne int basl_table_append_length(struct basl_table *table, uint8_t size); 9649b947c0SCorvin Köhne int basl_table_append_pointer(struct basl_table *table, 9749b947c0SCorvin Köhne const uint8_t src_signature[ACPI_NAMESEG_SIZE], uint8_t size); 9821bbc284SCorvin Köhne int basl_table_create(struct basl_table **table, struct vmctx *ctx, 9967654ffdSCorvin Köhne const uint8_t *name, uint32_t alignment); 100*24a0fef9SCorvin Köhne /* Adds the table to RSDT and XSDT */ 101*24a0fef9SCorvin Köhne int basl_table_register_to_rsdt(struct basl_table *table); 102