diff mbox series

[v5,05/18] ACPI: utils: Add an acpi_sta_enabled() helper and use it in acpi_processor_make_present()

Message ID 20240412143719.11398-6-Jonathan.Cameron@huawei.com
State New
Headers show
Series ACPI/arm64: add support for virtual cpu hotplug | expand

Commit Message

Jonathan Cameron April 12, 2024, 2:37 p.m. UTC
A device is enabled only if both the present and enabled bits
are set in the result of calling the _STA method, or the
_STA method is not present (in which case the device is always
present and enabled).

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

---
v5: New patch
---
 drivers/acpi/acpi_processor.c |  8 +++-----
 drivers/acpi/utils.c          | 21 +++++++++++++++++++++
 include/acpi/acpi_bus.h       |  1 +
 3 files changed, 25 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index 05264722c207..3aa43dee4391 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -185,8 +185,6 @@  static void __init acpi_pcc_cpufreq_init(void) {}
 /* Initialization */
 static int acpi_processor_make_present(struct acpi_processor *pr)
 {
-	unsigned long long sta;
-	acpi_status status;
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_ACPI_HOTPLUG_CPU))
@@ -195,9 +193,9 @@  static int acpi_processor_make_present(struct acpi_processor *pr)
 	if (invalid_phys_cpuid(pr->phys_id))
 		return -ENODEV;
 
-	status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
-	if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT))
-		return -ENODEV;
+	ret = acpi_sta_enabled(pr->handle);
+	if (ret)
+		return ret;
 
 	cpu_maps_update_begin();
 	cpus_write_lock();
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 202234ba54bd..3004426b218c 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -744,6 +744,27 @@  acpi_status acpi_evaluate_reg(acpi_handle handle, u8 space_id, u32 function)
 }
 EXPORT_SYMBOL(acpi_evaluate_reg);
 
+int acpi_sta_enabled(acpi_handle handle)
+{
+	unsigned long long sta;
+	bool present, enabled;
+	acpi_status status;
+
+	if (acpi_has_method(handle, "_STA")) {
+		status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
+		if (ACPI_FAILURE(status))
+			return -ENODEV;
+
+		present = sta & ACPI_STA_DEVICE_PRESENT;
+		enabled = sta & ACPI_STA_DEVICE_ENABLED;
+		if (!present || !enabled) {
+			return -EPROBE_DEFER;
+		}
+		return 0;
+	}
+	return 0; /* No _STA means always on! */
+}
+
 /**
  * acpi_evaluate_dsm - evaluate device's _DSM method
  * @handle: ACPI device handle
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 5de954e2b18a..e193507fd743 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -51,6 +51,7 @@  bool acpi_ata_match(acpi_handle handle);
 bool acpi_bay_match(acpi_handle handle);
 bool acpi_dock_match(acpi_handle handle);
 
+int acpi_sta_enabled(acpi_handle handle);
 bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs);
 union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
 			u64 rev, u64 func, union acpi_object *argv4);