xref: /freebsd/usr.sbin/bhyve/acpi_device.h (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
5  * Author: Corvin Köhne <c.koehne@beckhoff.com>
6  */
7 
8 #pragma once
9 
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wunused-parameter"
12 #include <contrib/dev/acpica/include/acpi.h>
13 #pragma GCC diagnostic pop
14 
15 struct vmctx;
16 
17 struct acpi_device;
18 
19 /**
20  * Device specific information and emulation.
21  *
22  * @param name        Used as device name in the DSDT.
23  * @param hid         Used as _HID in the DSDT.
24  * @param build_table Called to build a device specific ACPI table like the TPM2
25  *                    table.
26  * @param write_dsdt  Called to append the DSDT with device specific
27  *                    information.
28  */
29 struct acpi_device_emul {
30 	const char *name;
31 	const char *hid;
32 
33 	int (*build_table)(const struct acpi_device *dev);
34 	int (*write_dsdt)(const struct acpi_device *dev);
35 };
36 
37 /**
38  * Creates an ACPI device.
39  *
40  * @param[out] new_dev Returns the newly create ACPI device.
41  * @param[in]  softc   Pointer to the software context of the ACPI device.
42  * @param[in]  vm_ctx  VM context the ACPI device is created in.
43  * @param[in]  emul    Device emulation struct. It contains some information
44  *                     like the name of the ACPI device and some device specific
45  *                     functions.
46  */
47 int acpi_device_create(struct acpi_device **new_dev, void *softc,
48     struct vmctx *vm_ctx, const struct acpi_device_emul *emul);
49 void acpi_device_destroy(struct acpi_device *dev);
50 
51 int acpi_device_add_res_fixed_ioport(struct acpi_device *dev, UINT16 port,
52     UINT8 length);
53 int acpi_device_add_res_fixed_memory32(struct acpi_device *dev,
54     UINT8 write_protected, UINT32 address, UINT32 length);
55 
56 void *acpi_device_get_softc(const struct acpi_device *dev);
57 
58 int acpi_device_build_table(const struct acpi_device *dev);
59 int acpi_device_write_dsdt(const struct acpi_device *dev);
60