ANDROID: arm64: Support for extracting EAS energy costs from DT

This patch implements support for extracting energy cost data from DT.
The data should conform to the DT bindings for energy cost data needed
by EAS (energy aware scheduling).

This patch supercedes the previous EAS patches:

 arm64, topology: Updates to use DT bindings for EAS costing data
 sched: Support for extracting EAS energy costs from DT
 arm64: use cpu scale value derived from energy model
 arm64: define hikey620 sys sd energy model
 arm64: introduce sys sd energy model infrastructure
 arm64: factor out energy model from topology shim layer
 arm64, topology: Define JUNO energy and provide it to the scheduler

There is no need to introduce code and replace it with the Android
expression of the same code in this stack.

Note that if sched-energy-costs is present at runtime, you can no longer
write cpu_capacity.

Some platforms may not provide capacity-dmips-mhz, but instead provide
an energy model in sched-energy-costs format. In this case, ensure that
the max capacity defined in the energy model is used as the raw capacity
value and that the arch_topology driver can still be loaded.
This ensures that the topology details are still available in sysfs and
also that the required flags are set.
Reported-by: Quentin Perret <quentin.perret@arm.com>

Further note that the arm support is still using a built-in energy
model, i.e. only arm64 platforms are able to provide energy model
data through the sched-energy-costs node in DT.

Change-Id: Id617b08eaf08cff3a099f35aeedbda72bb826ce6
Signed-off-by: Juri Lelli <juri.lelli@arm.com>
Signed-off-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Robin Randhawa <robin.randhawa@arm.com>
(modified to apply to 4.14 and updated to override dmips-mhz)
Signed-off-by: Chris Redpath <chris.redpath@arm.com>
diff --git a/include/linux/sched_energy.h b/include/linux/sched_energy.h
new file mode 100644
index 0000000..83d7178
--- /dev/null
+++ b/include/linux/sched_energy.h
@@ -0,0 +1,41 @@
+#ifndef _LINUX_SCHED_ENERGY_H
+#define _LINUX_SCHED_ENERGY_H
+
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+/*
+ * There doesn't seem to be an NR_CPUS style max number of sched domain
+ * levels so here's an arbitrary constant one for the moment.
+ *
+ * The levels alluded to here correspond to entries in struct
+ * sched_domain_topology_level that are meant to be populated by arch
+ * specific code (topology.c).
+ */
+#define NR_SD_LEVELS 8
+
+#define SD_LEVEL0   0
+#define SD_LEVEL1   1
+#define SD_LEVEL2   2
+#define SD_LEVEL3   3
+#define SD_LEVEL4   4
+#define SD_LEVEL5   5
+#define SD_LEVEL6   6
+#define SD_LEVEL7   7
+
+/*
+ * Convenience macro for iterating through said sd levels.
+ */
+#define for_each_possible_sd_level(level)		    \
+	for (level = 0; level < NR_SD_LEVELS; level++)
+
+extern struct sched_group_energy *sge_array[NR_CPUS][NR_SD_LEVELS];
+
+#ifdef CONFIG_GENERIC_ARCH_TOPOLOGY
+void init_sched_energy_costs(void);
+int sched_energy_installed(int cpu);
+#else
+void init_sched_energy_costs(void) {}
+#endif
+
+#endif