From 1e0d9471ab6cee33c1df19f362aa65474119da47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20S=C5=82omi=C5=84ski?= Date: Sat, 9 Mar 2024 16:33:12 +0100 Subject: [PATCH] core/opregion: Avoid needless loads for fields marked Preserve Closes #144. --- core/opregion.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/opregion.c b/core/opregion.c index beda0c6..4ad0976 100644 --- a/core/opregion.c +++ b/core/opregion.c @@ -482,7 +482,17 @@ void lai_write_field_internal(uint8_t *source, lai_nsnode_t *field) { uint64_t value; if (write_flag == FIELD_PRESERVE) { - if (field->type == LAI_NAMESPACE_FIELD || field->type == LAI_NAMESPACE_BANKFIELD) { + if (access_size == access_bits) { + // Don't needlessly read from the field if we're going to replace all of the bits. + // This is more in line with ACPICA's behavior, and the additional reads could've + // potentially confused hardware. + + // If we're accessing the whole word, we can't start anywhere else. + LAI_ENSURE(bit_offset == 0); + + value = 0; + } else if (field->type == LAI_NAMESPACE_FIELD + || field->type == LAI_NAMESPACE_BANKFIELD) { value = lai_perform_read(field->fld_region_node, access_size, offset); } else if (field->type == LAI_NAMESPACE_INDEXFIELD) { value = lai_perform_indexfield_read(field, access_size, offset);