acpi_spmc(4): Factor out testing for present DSMs/functions

Since we are now keeping in the softc the information about which DSM
functions are available (in supported_functions[]), the 'dsms' field
there is somewhat redundant.

Make it completely redundant by keeping the bit representing the
enumeration function itself in each element of supported_functions[],
and then remove the field.

As a result, convert has_dsm() to rely on supports_function().

Adapt acpi_spmc_dsm_check_functions() so that it does not take into
account the enumeration function bit.

While here, use the self-explanatory stance
IDX_TO_BIT(DSM_ENUM_FUNCTIONS) instead of a hardcoded 1.

Reviewed by:    obiwac
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D56878
This commit is contained in:
Olivier Certner
2026-05-06 11:31:19 +02:00
parent d765d209c3
commit ba4f05b55f
+16 -8
View File
@@ -223,7 +223,6 @@ struct acpi_spmc_constraint {
struct acpi_spmc_softc {
device_t dev;
ACPI_HANDLE handle;
int dsms;
uint64_t supported_functions[nitems(dsms)];
struct eventhandler_entry *eh_suspend;
@@ -257,7 +256,7 @@ supports_function(const struct acpi_spmc_softc *const sc, const int dsm_index,
static bool
has_dsm(const struct acpi_spmc_softc *const sc, const int dsm_index)
{
return ((sc->dsms & IDX_TO_BIT(dsm_index)) != 0);
return (supports_function(sc, dsm_index, DSM_ENUM_FUNCTIONS));
}
typedef const char *pbf_get_name_t(const int, const void *const);
@@ -371,6 +370,7 @@ acpi_spmc_attach(device_t dev)
{
struct acpi_spmc_softc *const sc = device_get_softc(dev);
const ACPI_HANDLE handle = acpi_get_handle(dev);
int supported_dsms;
char buf[32];
int error;
@@ -382,6 +382,7 @@ acpi_spmc_attach(device_t dev)
sc->dev = dev;
sc->handle = handle;
supported_dsms = 0;
for (int i = 0; i < nitems(dsms); ++i) {
KASSERT(dsms[i] != NULL, ("%s: Sparse dsms[]!", __func__));
KASSERT(dsms[i]->index == i,
@@ -389,14 +390,17 @@ acpi_spmc_attach(device_t dev)
dsms[i]->name));
acpi_spmc_probe_dsm(sc, dsms[i]);
if (has_dsm(sc, i))
supported_dsms |= IDX_TO_BIT(i);
}
if (sc->dsms == 0) {
if (supported_dsms == 0) {
device_printf(dev, "No DSM supported!");
return (ENXIO);
}
print_bit_field(buf, sizeof(buf), sc->dsms, "DSM", pbf_dsm_name, NULL);
print_bit_field(buf, sizeof(buf), supported_dsms, "DSM",
pbf_dsm_name, NULL);
device_printf(dev, "DSMs supported: %s\n", buf);
/* Print supported functions of usable DSMs. */
@@ -436,7 +440,12 @@ static void
acpi_spmc_dsm_print_functions(const struct acpi_spmc_softc *const sc,
const struct dsm_desc *const dsm)
{
const uint64_t supported_functions =
/*
* Remove the enumeration function bit, which we do not care about when
* printing which functions are supported and which we do not want to
* report as unknown.
*/
const uint64_t supported_functions = ~IDX_TO_BIT(DSM_ENUM_FUNCTIONS) &
sc->supported_functions[dsm->index];
const uint64_t missing = dsm->expected_functions & ~supported_functions;
const uint64_t unknown = supported_functions &
@@ -475,10 +484,9 @@ acpi_spmc_probe_dsm(struct acpi_spmc_softc *const sc,
/*
* DSM is supported if bit 0 is set.
*/
if ((supported_functions & 1) == 0)
if ((supported_functions & IDX_TO_BIT(DSM_ENUM_FUNCTIONS)) == 0)
return;
sc->supported_functions[dsm->index] = supported_functions & ~1;
sc->dsms |= IDX_TO_BIT(dsm->index);
sc->supported_functions[dsm->index] = supported_functions;
}
static void