summaryrefslogtreecommitdiff
path: root/src/hal-backend-power.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hal-backend-power.c')
-rw-r--r--src/hal-backend-power.c95
1 files changed, 12 insertions, 83 deletions
diff --git a/src/hal-backend-power.c b/src/hal-backend-power.c
index b25ad6f..18ec8db 100644
--- a/src/hal-backend-power.c
+++ b/src/hal-backend-power.c
@@ -542,100 +542,29 @@ static int memory_set_fault_around_bytes(char *res_name,
static int power_init(void **data)
{
hal_backend_power_funcs *power_funcs = NULL;
- struct pass_resource_cpu *cpu = NULL;
- struct pass_resource_bus *bus = NULL;
- struct pass_resource_gpu *gpu = NULL;
- struct pass_resource_memory *memory = NULL;
- int ret;
-
- /* Allocate memory */
- power_funcs = calloc(1, sizeof(hal_backend_power_funcs));
- if (!power_funcs)
- return -ENOMEM;
-
- cpu = calloc(1, sizeof(struct pass_resource_cpu));
- if (!cpu) {
- ret = -ENOMEM;
- goto err_funcs;
- }
-
- bus = calloc(1, sizeof(struct pass_resource_bus));
- if (!bus) {
- ret = -ENOMEM;
- goto err_cpu;
- }
- gpu = calloc(1, sizeof(struct pass_resource_gpu));
- if (!gpu) {
- ret = -ENOMEM;
- goto err_bus;
- }
-
- memory = calloc(1, sizeof(struct pass_resource_memory));
- if (!memory) {
- ret = -ENOMEM;
- goto err_gpu;
- }
-
- /* Initialize each h/w resource */
- cpu->dvfs = cpufreq_dvfs_ops;
- cpu->hotplug = cpu_hotplus_ops;
- cpu->tmu = tmu_ops;
-
- bus->dvfs = devfreq_dvfs_ops;
- bus->tmu = tmu_ops;
+ if (!data)
+ return -EINVAL;
+ power_funcs = *(hal_backend_power_funcs **)data;
- gpu->dvfs = devfreq_dvfs_ops;
- gpu->tmu = tmu_ops;
+ power_funcs->cpu->dvfs = cpufreq_dvfs_ops;
+ power_funcs->cpu->hotplug = cpu_hotplus_ops;
+ power_funcs->cpu->tmu = tmu_ops;
- memory->get_fault_around_bytes = memory_get_fault_around_bytes;
- memory->set_fault_around_bytes = memory_set_fault_around_bytes;
+ power_funcs->bus->dvfs = devfreq_dvfs_ops;
+ power_funcs->bus->tmu = tmu_ops;
- /* Initialize hal_backend_power_funcs */
- power_funcs->cpu = cpu;
- power_funcs->bus = bus;
- power_funcs->gpu = gpu;
- power_funcs->memory = memory;
+ power_funcs->gpu->dvfs = devfreq_dvfs_ops;
+ power_funcs->gpu->tmu = tmu_ops;
- *data = (void *)power_funcs;
+ power_funcs->memory->get_fault_around_bytes = memory_get_fault_around_bytes;
+ power_funcs->memory->set_fault_around_bytes = memory_set_fault_around_bytes;
return 0;
-
-err_gpu:
- if (gpu)
- free(gpu);
-err_bus:
- if (bus)
- free(bus);
-err_cpu:
- if (cpu)
- free(cpu);
-err_funcs:
- free(power_funcs);
-
- return ret;
}
static int power_exit(void *data)
{
- hal_backend_power_funcs *funcs;
-
- if (!data)
- return -EINVAL;
-
- funcs = (hal_backend_power_funcs *)data;
-
- if (funcs->cpu)
- free(funcs->cpu);
- if (funcs->bus)
- free(funcs->bus);
- if (funcs->gpu)
- free(funcs->gpu);
- if (funcs->memory)
- free(funcs->memory);
-
- free(funcs);
-
return 0;
}