Add Witherspoon Power Supply policy
Create an error if a power supply is removed
while the system is powered on
Resolves openbmc/openbmc#1860
Change-Id: I7456505bb16771e9fd6edad9ebf6c28dbd0b7824
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/dbus/phosphor-dbus-monitor-config-native%.bbappend b/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/dbus/phosphor-dbus-monitor-config-native%.bbappend
index eebe9fa..7de97f3 100644
--- a/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/dbus/phosphor-dbus-monitor-config-native%.bbappend
+++ b/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/dbus/phosphor-dbus-monitor-config-native%.bbappend
@@ -1,2 +1,3 @@
PHOSPHOR_DBUS_MONITOR_CONFIGS_append = " witherspoon-fan-policy-native"
PHOSPHOR_DBUS_MONITOR_CONFIGS_append = " witherspoon-thermal-policy-native"
+PHOSPHOR_DBUS_MONITOR_CONFIGS_append = " witherspoon-power-supply-policy-native"
diff --git a/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-power-supply-policy-native.bb b/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-power-supply-policy-native.bb
new file mode 100644
index 0000000..4d234c1
--- /dev/null
+++ b/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-power-supply-policy-native.bb
@@ -0,0 +1,12 @@
+SUMMARY = "Power supply policy for Witherspoon"
+PR = "r1"
+
+inherit native
+inherit obmc-phosphor-license
+inherit phosphor-dbus-monitor
+
+SRC_URI += "file://power-supply-policy.yaml"
+
+do_install() {
+ install -D ${WORKDIR}/power-supply-policy.yaml ${D}${config_dir}/power-supply-policy.yaml
+}
diff --git a/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-power-supply-policy/power-supply-policy.yaml b/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-power-supply-policy/power-supply-policy.yaml
new file mode 100644
index 0000000..9d57404
--- /dev/null
+++ b/meta-openbmc-machines/meta-openpower/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-power-supply-policy/power-supply-policy.yaml
@@ -0,0 +1,157 @@
+# Witherspoon power supply policy for PDM.
+#
+# Create an error if a power supply is removed while the system is powered on
+
+- name: power supply0
+ class: group
+ group: path
+ members:
+ - meta: POWER SUPPLY
+ path: /xyz/openbmc_project/inventory/system/chassis/power_supply0
+
+- name: power supply1
+ class: group
+ group: path
+ members:
+ - meta: POWER SUPPLY
+ path: /xyz/openbmc_project/inventory/system/chassis/power_supply1
+
+- name: power supplies
+ description: >
+ 'A Witherspoon has two power supplies to monitor.'
+ class: group
+ group: path
+ members:
+ - meta: POWER SUPPLY
+ path: /xyz/openbmc_project/inventory/system/chassis/power_supply0
+ - meta: POWER SUPPLY
+ path: /xyz/openbmc_project/inventory/system/chassis/power_supply1
+
+- name: chassis state
+ description: >
+ 'A Witherspoon has a single chassis to monitor.'
+ class: group
+ group: path
+ members:
+ - meta: CHASSISSTATE
+ path: /xyz/openbmc_project/state/chassis0
+
+- name: power supply present
+ description: >
+ 'Monitor the presence state of each power supply.'
+ class: group
+ group: property
+ type: boolean
+ members:
+ - interface: xyz.openbmc_project.Inventory.Item
+ meta: PRESENT
+ property: Present
+
+- name: chassis powered
+ description: >
+ 'Monitor the chassis power state.'
+ class: group
+ group: property
+ type: string
+ members:
+ - interface: xyz.openbmc_project.State.Chassis
+ meta: CHASSIS_STATE
+ property: CurrentPowerState
+
+- name: watch power supply present
+ description: >
+ 'Trigger logic on power supply presence state changes.'
+ class: watch
+ watch: property
+ paths: power supplies
+ properties: power supply present
+ callback: check power
+
+- name: watch chassis state
+ description: >
+ 'Trigger logic on chassis power state changes.'
+ class: watch
+ watch: property
+ paths: chassis state
+ properties: chassis powered
+ callback: check power
+
+- name: check power
+ description: >
+ 'If the chassis has power, check for power supplies.'
+ class: condition
+ condition: count
+ paths: chassis state
+ properties: chassis powered
+ callback: check power supplies
+ countop: '>'
+ countbound: 0
+ op: '=='
+ bound: xyz.openbmc_project.State.Chassis.PowerState.On
+
+- name: check power supplies
+ description: >
+ 'Create an error if a power supply is not present.'
+ class: callback
+ callback: group
+ members:
+ - check power supply0 presence
+ - check power supply1 presence
+
+- name: check power supply0 presence
+ description: >
+ 'If this condition passes power supply0 has been unplugged for more than
+ 5 seconds. Count present power supplies rather than non-present
+ power supplies since the latter would pass if the power supply has not
+ been created for some reason.
+
+ For a more detailed definition of unplugged, consult the documentation
+ of xyz.openbmc_project.Inventory.Item and/or the documentation
+ of the power supply inventory object implementation.'
+ class: condition
+ condition: count
+ paths: power supply0
+ properties: power supply present
+ defer: 5000000us
+ callback: notpresent power supply0 error
+ countop: '<'
+ countbound: 1
+ op: '=='
+ bound: true
+
+- name: check power supply1 presence
+ description: >
+ 'If this condition passes power supply1 has been unplugged for more than
+ 5 seconds.'
+ class: condition
+ condition: count
+ paths: power supply1
+ properties: power supply present
+ defer: 5000000us
+ callback: notpresent power supply1 error
+ countop: '<'
+ countbound: 1
+ op: '=='
+ bound: true
+
+- name: notpresent power supply0 error
+ class: callback
+ callback: elog
+ paths: power supply0
+ properties: power supply present
+ error: xyz::openbmc_project::Inventory::Error::NotPresent
+ metadata:
+ - name: xyz::openbmc_project::Inventory::NotPresent::CALLOUT_INVENTORY_PATH
+ value: /xyz/openbmc_project/inventory/system/chassis/power_supply0
+ type: string
+
+- name: notpresent power supply1 error
+ class: callback
+ callback: elog
+ paths: power supply1
+ properties: power supply present
+ error: xyz::openbmc_project::Inventory::Error::NotPresent
+ metadata:
+ - name: xyz::openbmc_project::Inventory::NotPresent::CALLOUT_INVENTORY_PATH
+ value: /xyz/openbmc_project/inventory/system/chassis/power_supply1
+ type: string