regulators: Only configure/monitor if present
Enhance the configure and monitor operations to only be performed if the
device is present.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I57fed4f92937b808ac6f8c37899e28d6009747e6
diff --git a/phosphor-regulators/src/device.cpp b/phosphor-regulators/src/device.cpp
index 1290077..8ae7afb 100644
--- a/phosphor-regulators/src/device.cpp
+++ b/phosphor-regulators/src/device.cpp
@@ -69,27 +69,34 @@
void Device::configure(Services& services, System& system, Chassis& chassis)
{
- // If configuration changes are defined for this device, apply them
- if (configuration)
+ // Verify device is present
+ if (isPresent(services, system, chassis))
{
- configuration->execute(services, system, chassis, *this);
- }
+ // If configuration changes are defined for this device, apply them
+ if (configuration)
+ {
+ configuration->execute(services, system, chassis, *this);
+ }
- // Configure rails
- for (std::unique_ptr<Rail>& rail : rails)
- {
- rail->configure(services, system, chassis, *this);
+ // Configure rails
+ for (std::unique_ptr<Rail>& rail : rails)
+ {
+ rail->configure(services, system, chassis, *this);
+ }
}
}
void Device::monitorSensors(Services& services, System& system,
Chassis& chassis)
{
-
- // Monitor sensors in each rail
- for (std::unique_ptr<Rail>& rail : rails)
+ // Verify device is present
+ if (isPresent(services, system, chassis))
{
- rail->monitorSensors(services, system, chassis, *this);
+ // Monitor sensors in each rail
+ for (std::unique_ptr<Rail>& rail : rails)
+ {
+ rail->monitorSensors(services, system, chassis, *this);
+ }
}
}
diff --git a/phosphor-regulators/src/device.hpp b/phosphor-regulators/src/device.hpp
index 75ff904..8ef37fb 100644
--- a/phosphor-regulators/src/device.hpp
+++ b/phosphor-regulators/src/device.hpp
@@ -184,6 +184,25 @@
}
/**
+ * Returns whether this device is present.
+ *
+ * @return true if device is present, false otherwise
+ */
+ bool isPresent(Services& services, System& system, Chassis& chassis)
+ {
+ if (presenceDetection)
+ {
+ // Execute presence detection to determine if device is present
+ return presenceDetection->execute(services, system, chassis, *this);
+ }
+ else
+ {
+ // No presence detection defined; assume device is present
+ return true;
+ }
+ }
+
+ /**
* Returns whether this device is a voltage regulator.
*
* @return true if device is a voltage regulator, false otherwise