aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShreyas B. Prabhu <shreyas@linux.vnet.ibm.com>2016-06-17 09:51:44 +0530
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-06-20 14:32:47 +1000
commit326683591db968f7835d9aef7c0699ef8e158b30 (patch)
treef23524449f54a8341d99d1856daaf50a688eb30b
parentc600283f603281c0dc44e62243a2dfcfe1dbee07 (diff)
downloadskiboot-326683591db968f7835d9aef7c0699ef8e158b30.zip
skiboot-326683591db968f7835d9aef7c0699ef8e158b30.tar.gz
skiboot-326683591db968f7835d9aef7c0699ef8e158b30.tar.bz2
slw: Simplify if-condition while adding idle states to device tree
if-condition in add_cpu_idle_state_properties which checks if a given idle state is supported is bloated with multiple '&' and '||' operations. Simplify by adding a mask variable and setting the relevant bits. This patch does not change any functionality. Acked-by: Michael Neuling <mikey@neuling.org> Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--hw/slw.c73
1 files changed, 43 insertions, 30 deletions
diff --git a/hw/slw.c b/hw/slw.c
index b67097c..53e02cc 100644
--- a/hw/slw.c
+++ b/hw/slw.c
@@ -500,6 +500,8 @@ void add_cpu_idle_state_properties(void)
bool can_sleep = true, can_winkle = true;
u8 i;
+ u32 supported_states_mask;
+
/* Buffers to hold idle state properties */
char *name_buf, *alloced_name_buf;
u32 *latency_ns_buf;
@@ -589,38 +591,49 @@ void add_cpu_idle_state_properties(void)
name_buf_len = 0;
num_supported_idle_states = 0;
+ /*
+ * Create a mask with the flags of all supported idle states
+ * set. Use this to only add supported idle states to the
+ * device-tree
+ */
+ supported_states_mask = OPAL_PM_NAP_ENABLED;
+ if (can_sleep)
+ supported_states_mask |= OPAL_PM_SLEEP_ENABLED |
+ OPAL_PM_SLEEP_ENABLED_ER1;
+ if (can_winkle)
+ supported_states_mask |= OPAL_PM_WINKLE_ENABLED;
+
for (i = 0; i < nr_states; i++) {
/* For each state, check if it is one of the supported states. */
- if( (states[i].flags & OPAL_PM_NAP_ENABLED) ||
- ((states[i].flags & OPAL_PM_SLEEP_ENABLED) && can_sleep) ||
- ((states[i].flags & OPAL_PM_SLEEP_ENABLED_ER1) && can_sleep) ||
- ((states[i].flags & OPAL_PM_WINKLE_ENABLED) && can_winkle) ) {
- /*
- * If a state is supported add each of its property
- * to its corresponding property buffer.
- */
- strcpy(name_buf, states[i].name);
- name_buf = name_buf + strlen(states[i].name) + 1;
-
- *latency_ns_buf = cpu_to_fdt32(states[i].latency_ns);
- latency_ns_buf++;
-
- *residency_ns_buf = cpu_to_fdt32(states[i].residency_ns);
- residency_ns_buf++;
-
- *flags_buf = cpu_to_fdt32(states[i].flags);
- flags_buf++;
-
- *pmicr_buf = cpu_to_fdt64(states[i].pmicr);
- pmicr_buf++;
-
- *pmicr_mask_buf = cpu_to_fdt64(states[i].pmicr);
- pmicr_mask_buf++;
-
- /* Increment buffer length trackers */
- name_buf_len += strlen(states[i].name) + 1;
- num_supported_idle_states++;
- }
+ if (!(states[i].flags & supported_states_mask))
+ continue;
+
+ /*
+ * If a state is supported add each of its property
+ * to its corresponding property buffer.
+ */
+ strcpy(name_buf, states[i].name);
+ name_buf = name_buf + strlen(states[i].name) + 1;
+
+ *latency_ns_buf = cpu_to_fdt32(states[i].latency_ns);
+ latency_ns_buf++;
+
+ *residency_ns_buf = cpu_to_fdt32(states[i].residency_ns);
+ residency_ns_buf++;
+
+ *flags_buf = cpu_to_fdt32(states[i].flags);
+ flags_buf++;
+
+ *pmicr_buf = cpu_to_fdt64(states[i].pmicr);
+ pmicr_buf++;
+
+ *pmicr_mask_buf = cpu_to_fdt64(states[i].pmicr);
+ pmicr_mask_buf++;
+
+ /* Increment buffer length trackers */
+ name_buf_len += strlen(states[i].name) + 1;
+ num_supported_idle_states++;
+
}
/* Point buffer pointers back to beginning of the buffer */