Commit 82ac62d1 authored by David Brazdil's avatar David Brazdil Committed by Marc Zyngier

psci: Replace psci_function_id array with a struct

Small refactor that replaces array of v0.1 function IDs indexed by an
enum of function-name constants with a struct of function IDs "indexed"
by field names. This is done in preparation for exposing the IDs to
other parts of the kernel. Exposing a struct avoids the need for
bounds checking.
Signed-off-by: default avatarDavid Brazdil <dbrazdil@google.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20201202184122.26046-6-dbrazdil@google.com
parent 0bc7474f
...@@ -58,15 +58,14 @@ typedef unsigned long (psci_fn)(unsigned long, unsigned long, ...@@ -58,15 +58,14 @@ typedef unsigned long (psci_fn)(unsigned long, unsigned long,
unsigned long, unsigned long); unsigned long, unsigned long);
static psci_fn *invoke_psci_fn; static psci_fn *invoke_psci_fn;
enum psci_function { struct psci_0_1_function_ids {
PSCI_FN_CPU_SUSPEND, u32 cpu_suspend;
PSCI_FN_CPU_ON, u32 cpu_on;
PSCI_FN_CPU_OFF, u32 cpu_off;
PSCI_FN_MIGRATE, u32 migrate;
PSCI_FN_MAX,
}; };
static u32 psci_function_id[PSCI_FN_MAX]; static struct psci_0_1_function_ids psci_0_1_function_ids;
#define PSCI_0_2_POWER_STATE_MASK \ #define PSCI_0_2_POWER_STATE_MASK \
(PSCI_0_2_POWER_STATE_ID_MASK | \ (PSCI_0_2_POWER_STATE_ID_MASK | \
...@@ -178,7 +177,7 @@ static int __psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point) ...@@ -178,7 +177,7 @@ static int __psci_cpu_suspend(u32 fn, u32 state, unsigned long entry_point)
static int psci_0_1_cpu_suspend(u32 state, unsigned long entry_point) static int psci_0_1_cpu_suspend(u32 state, unsigned long entry_point)
{ {
return __psci_cpu_suspend(psci_function_id[PSCI_FN_CPU_SUSPEND], return __psci_cpu_suspend(psci_0_1_function_ids.cpu_suspend,
state, entry_point); state, entry_point);
} }
...@@ -198,7 +197,7 @@ static int __psci_cpu_off(u32 fn, u32 state) ...@@ -198,7 +197,7 @@ static int __psci_cpu_off(u32 fn, u32 state)
static int psci_0_1_cpu_off(u32 state) static int psci_0_1_cpu_off(u32 state)
{ {
return __psci_cpu_off(psci_function_id[PSCI_FN_CPU_OFF], state); return __psci_cpu_off(psci_0_1_function_ids.cpu_off, state);
} }
static int psci_0_2_cpu_off(u32 state) static int psci_0_2_cpu_off(u32 state)
...@@ -216,7 +215,7 @@ static int __psci_cpu_on(u32 fn, unsigned long cpuid, unsigned long entry_point) ...@@ -216,7 +215,7 @@ static int __psci_cpu_on(u32 fn, unsigned long cpuid, unsigned long entry_point)
static int psci_0_1_cpu_on(unsigned long cpuid, unsigned long entry_point) static int psci_0_1_cpu_on(unsigned long cpuid, unsigned long entry_point)
{ {
return __psci_cpu_on(psci_function_id[PSCI_FN_CPU_ON], cpuid, entry_point); return __psci_cpu_on(psci_0_1_function_ids.cpu_on, cpuid, entry_point);
} }
static int psci_0_2_cpu_on(unsigned long cpuid, unsigned long entry_point) static int psci_0_2_cpu_on(unsigned long cpuid, unsigned long entry_point)
...@@ -234,7 +233,7 @@ static int __psci_migrate(u32 fn, unsigned long cpuid) ...@@ -234,7 +233,7 @@ static int __psci_migrate(u32 fn, unsigned long cpuid)
static int psci_0_1_migrate(unsigned long cpuid) static int psci_0_1_migrate(unsigned long cpuid)
{ {
return __psci_migrate(psci_function_id[PSCI_FN_MIGRATE], cpuid); return __psci_migrate(psci_0_1_function_ids.migrate, cpuid);
} }
static int psci_0_2_migrate(unsigned long cpuid) static int psci_0_2_migrate(unsigned long cpuid)
...@@ -548,22 +547,22 @@ static int __init psci_0_1_init(struct device_node *np) ...@@ -548,22 +547,22 @@ static int __init psci_0_1_init(struct device_node *np)
psci_ops.get_version = psci_0_1_get_version; psci_ops.get_version = psci_0_1_get_version;
if (!of_property_read_u32(np, "cpu_suspend", &id)) { if (!of_property_read_u32(np, "cpu_suspend", &id)) {
psci_function_id[PSCI_FN_CPU_SUSPEND] = id; psci_0_1_function_ids.cpu_suspend = id;
psci_ops.cpu_suspend = psci_0_1_cpu_suspend; psci_ops.cpu_suspend = psci_0_1_cpu_suspend;
} }
if (!of_property_read_u32(np, "cpu_off", &id)) { if (!of_property_read_u32(np, "cpu_off", &id)) {
psci_function_id[PSCI_FN_CPU_OFF] = id; psci_0_1_function_ids.cpu_off = id;
psci_ops.cpu_off = psci_0_1_cpu_off; psci_ops.cpu_off = psci_0_1_cpu_off;
} }
if (!of_property_read_u32(np, "cpu_on", &id)) { if (!of_property_read_u32(np, "cpu_on", &id)) {
psci_function_id[PSCI_FN_CPU_ON] = id; psci_0_1_function_ids.cpu_on = id;
psci_ops.cpu_on = psci_0_1_cpu_on; psci_ops.cpu_on = psci_0_1_cpu_on;
} }
if (!of_property_read_u32(np, "migrate", &id)) { if (!of_property_read_u32(np, "migrate", &id)) {
psci_function_id[PSCI_FN_MIGRATE] = id; psci_0_1_function_ids.migrate = id;
psci_ops.migrate = psci_0_1_migrate; psci_ops.migrate = psci_0_1_migrate;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment