bhyve: maintain a list of acpi devices

The list is used to generate the dsdt entry for every acpi device.

Reviewed by:		markj
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D3830
This commit is contained in:
Corvin Köhne 2021-10-07 16:14:31 +02:00
parent 682a522d61
commit fbd045021d
No known key found for this signature in database
GPG Key ID: D854DA56315E026A
3 changed files with 38 additions and 0 deletions

View File

@ -106,6 +106,30 @@ struct basl_fio {
#define EFFLUSH(x) \
if (fflush(x) != 0) goto err_exit;
/*
* A list for additional ACPI devices like a TPM.
*/
struct acpi_device_list_entry {
SLIST_ENTRY(acpi_device_list_entry) chain;
const struct acpi_device *dev;
};
static SLIST_HEAD(acpi_device_list,
acpi_device_list_entry) acpi_devices = SLIST_HEAD_INITIALIZER(acpi_devices);
int
acpi_tables_add_device(const struct acpi_device *const dev)
{
struct acpi_device_list_entry *const entry = calloc(1, sizeof(*entry));
if (entry == NULL) {
return (ENOMEM);
}
entry->dev = dev;
SLIST_INSERT_HEAD(&acpi_devices, entry, chain);
return (0);
}
/*
* Helper routines for writing to the DSDT from other modules.
*/
@ -219,6 +243,11 @@ basl_fwrite_dsdt(FILE *fp)
vmgenc_write_dsdt();
const struct acpi_device_list_entry *entry;
SLIST_FOREACH(entry, &acpi_devices, chain) {
acpi_device_write_dsdt(entry->dev);
}
dsdt_line("}");
if (dsdt_error != 0)

View File

@ -31,6 +31,8 @@
#ifndef _ACPI_H_
#define _ACPI_H_
#include "acpi_device.h"
#define SCI_INT 9
#define SMI_CMD 0xb2
@ -55,6 +57,7 @@ struct vmctx;
int acpi_build(struct vmctx *ctx, int ncpu);
void acpi_raise_gpe(struct vmctx *ctx, unsigned bit);
int acpi_tables_add_device(const struct acpi_device *const dev);
void dsdt_line(const char *fmt, ...);
void dsdt_fixed_ioport(uint16_t iobase, uint16_t length);
void dsdt_fixed_irq(uint8_t irq);

View File

@ -68,6 +68,12 @@ acpi_device_create(struct acpi_device **const new_dev,
return (ENOMEM);
}
const int error = acpi_tables_add_device(dev);
if (error) {
acpi_device_destroy(dev);
return (error);
}
*new_dev = dev;
return (0);