/*
- * PASS (Power Aware System Service)
+ * HAL backend for hal-api-power which is used for PASS daemon
*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include <errno.h>
#include <limits.h>
-#include <pass/hal.h>
-#include <pass/hal-log.h>
#include <stdio.h>
#include <stdlib.h>
-#include "../shared/sysfs.h"
+#include <hal/hal-power-interface.h>
+
+#include "sysfs.h"
+
+#define BUFF_MAX 255
+/*************************
+ * H/W Resource Defintions
+ */
#define CPUFREQ_PATH_PREFIX "/sys/devices/system/cpu/"
#define CPUFREQ_CURR_GOVERNOR_PATH_SUFFIX "/cpufreq/scaling_governor"
#define CPUFREQ_AVAIL_GOVERNOR_PATH_SUFFIX "/cpufreq/scaling_available_governors"
#define TMU_POLICY_PATH_SUFFIX "/policy"
#define TMU_TEMP_MASK 0xFFFFF
-static int standard_dvfs_get_curr_governor(char *res_name, char *governor)
+#define FAULT_AROUND_BYTES_PATH "/sys/kernel/debug/fault_around_bytes"
+
+/*************************************************
+ * HAL backend implementation for CPU H/W Resource
+ */
+static int cpu_dvfs_get_curr_governor(char *res_name, char *governor)
{
char path[PATH_MAX];
int ret;
return 0;
}
-static int standard_dvfs_set_curr_governor(char *res_name, char *governor)
+static int cpu_dvfs_set_curr_governor(char *res_name, char *governor)
{
char path[PATH_MAX];
int ret;
return 0;
}
-static int standard_dvfs_get_curr_freq(char *res_name)
+static int cpu_dvfs_get_curr_freq(char *res_name)
{
char path[PATH_MAX];
int freq, ret;
return freq;
}
-static int standard_dvfs_get_min_freq(char *res_name)
+static int cpu_dvfs_get_min_freq(char *res_name)
{
char path[PATH_MAX];
int freq, ret;
return freq;
}
-static int standard_dvfs_set_min_freq(char *res_name, int freq)
+static int cpu_dvfs_set_min_freq(char *res_name, int freq)
{
char path[PATH_MAX];
int ret;
return 0;
}
-static int standard_dvfs_get_max_freq(char *res_name)
+static int cpu_dvfs_get_max_freq(char *res_name)
{
char path[PATH_MAX];
int freq, ret;
return freq;
}
-static int standard_dvfs_set_max_freq(char *res_name, int freq)
+static int cpu_dvfs_set_max_freq(char *res_name, int freq)
{
char path[PATH_MAX];
int ret;
return 0;
}
-static int standard_dvfs_get_available_min_freq(char *res_name)
+static int cpu_dvfs_get_available_min_freq(char *res_name)
{
char path[PATH_MAX];
int val, ret;
}
-static int standard_dvfs_get_available_max_freq(char *res_name)
+static int cpu_dvfs_get_available_max_freq(char *res_name)
{
char path[PATH_MAX];
int val, ret;
return val;
}
-static int standard_dvfs_get_up_threshold(char *res_name)
+static int cpu_dvfs_get_up_threshold(char *res_name)
{
char path[PATH_MAX];
int val, ret;
return val;
}
-static int standard_dvfs_set_up_threshold(char *res_name, int up_threshold)
+static int cpu_dvfs_set_up_threshold(char *res_name, int up_threshold)
{
char path[PATH_MAX];
int ret;
return 0;
}
-static struct pass_resource_dvfs_ops standard_cpu_dvfs_ops = {
- .get_curr_governor = standard_dvfs_get_curr_governor,
- .set_curr_governor = standard_dvfs_set_curr_governor,
- .get_curr_freq = standard_dvfs_get_curr_freq,
- .get_min_freq = standard_dvfs_get_min_freq,
- .set_min_freq = standard_dvfs_set_min_freq,
- .get_max_freq = standard_dvfs_get_max_freq,
- .set_max_freq = standard_dvfs_set_max_freq,
- .get_available_min_freq = standard_dvfs_get_available_min_freq,
- .get_available_max_freq = standard_dvfs_get_available_max_freq,
- .get_up_threshold = standard_dvfs_get_up_threshold,
- .set_up_threshold = standard_dvfs_set_up_threshold,
+static struct pass_resource_dvfs_ops cpu_dvfs_ops = {
+ .get_curr_governor = cpu_dvfs_get_curr_governor,
+ .set_curr_governor = cpu_dvfs_set_curr_governor,
+ .get_curr_freq = cpu_dvfs_get_curr_freq,
+ .get_min_freq = cpu_dvfs_get_min_freq,
+ .set_min_freq = cpu_dvfs_set_min_freq,
+ .get_max_freq = cpu_dvfs_get_max_freq,
+ .set_max_freq = cpu_dvfs_set_max_freq,
+ .get_available_min_freq = cpu_dvfs_get_available_min_freq,
+ .get_available_max_freq = cpu_dvfs_get_available_max_freq,
+ .get_up_threshold = cpu_dvfs_get_up_threshold,
+ .set_up_threshold = cpu_dvfs_set_up_threshold,
};
-static int standard_hotplug_get_online_state(char *res_name, int cpu)
+static int cpu_hotplug_get_online_state(char *res_name, int cpu)
{
char path[PATH_MAX];
int ret, online;
return online;
}
-static int standard_hotplug_set_online_state(char *res_name, int cpu, int on)
+static int cpu_hotplug_set_online_state(char *res_name, int cpu, int on)
{
char path[PATH_MAX];
int ret;
* opertaion.
*/
if (on == 0 && cpu == 0) {
- _E("cannot turn off the CPU0");
return 0;
}
return 0;
}
-static struct pass_resource_hotplug_ops standard_cpu_hotplus_ops = {
- .get_online_state = standard_hotplug_get_online_state,
- .set_online_state = standard_hotplug_set_online_state,
+static struct pass_resource_hotplug_ops cpu_hotplug_ops = {
+ .get_online_state = cpu_hotplug_get_online_state,
+ .set_online_state = cpu_hotplug_set_online_state,
.get_online_min_num = NULL,
.set_online_min_num = NULL,
.get_online_max_num = NULL,
.set_online_max_num = NULL,
};
-static int standard_tmu_get_temp(char *res_thermal_name)
+static int cpu_tmu_get_temp(char *res_thermal_name)
{
char path[PATH_MAX];
int temp, ret;
return (((temp & TMU_TEMP_MASK) + 500) / 1000);
}
-static int standard_tmu_get_policy(char *res_thermal_name, char *policy)
+static int cpu_tmu_get_policy(char *res_thermal_name, char *policy)
{
char path[PATH_MAX];
int ret;
return 0;
}
-static struct pass_resource_tmu_ops standard_cpu_tmu_ops = {
- .get_temp = standard_tmu_get_temp,
- .get_policy = standard_tmu_get_policy,
+static struct pass_resource_tmu_ops cpu_tmu_ops = {
+ .get_temp = cpu_tmu_get_temp,
+ .get_policy = cpu_tmu_get_policy,
};
-static int standard_cpu_open(char *res_name, struct pass_resource_info *info,
- struct pass_resource_common **common)
+/****************************************************
+ * HAL backend implementation for Memory H/W Resource
+ */
+static int memory_get_fault_around_bytes(char *res_name)
+{
+ int ret, fault_around_bytes;
+
+ if (!res_name)
+ return -EINVAL;
+
+ ret = sysfs_read_int(FAULT_AROUND_BYTES_PATH, &fault_around_bytes);
+ if (ret < 0)
+ return ret;
+
+ return fault_around_bytes;
+}
+
+static int memory_set_fault_around_bytes(char *res_name,
+ int fault_around_bytes)
{
- struct pass_resource_cpu *cpu_res;
+ int ret;
- if (!info)
+ if ((!res_name) || (fault_around_bytes <= 0))
return -EINVAL;
- cpu_res = calloc(1, sizeof(struct pass_resource_cpu));
- if (!cpu_res)
+ ret = sysfs_write_int(FAULT_AROUND_BYTES_PATH, fault_around_bytes);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+/************************
+ * HAL backend power data
+ */
+static int power_rpi4_init(void **data)
+{
+ hal_backend_power_funcs *power_funcs = NULL;
+ struct pass_resource_cpu *cpu = 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) {
return -ENOMEM;
+ goto err;
+ }
+
+ memory = calloc(1, sizeof(struct pass_resource_memory));
+ if (!memory) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ /* Initialize each h/w resource */
+ cpu->dvfs = cpu_dvfs_ops;
+ cpu->hotplug = cpu_hotplug_ops;
+ cpu->tmu = cpu_tmu_ops;
+
+ memory->get_fault_around_bytes = memory_get_fault_around_bytes;
+ memory->set_fault_around_bytes = memory_set_fault_around_bytes;
- cpu_res->common.info = info;
- cpu_res->dvfs = standard_cpu_dvfs_ops;
- cpu_res->hotplug = standard_cpu_hotplus_ops;
- cpu_res->tmu = standard_cpu_tmu_ops;
+ /* Initialize hal_backend_power_funcs */
+ power_funcs->cpu = cpu;
+ power_funcs->memory = memory;
- *common = (struct pass_resource_common *) cpu_res;
+ *data = (void *)power_funcs;
return 0;
+err:
+ if (memory)
+ free(memory);
+ if (cpu)
+ free(cpu);
+
+ free(power_funcs);
+
+ return ret;
}
-static int standard_cpu_close(char *res_name, struct pass_resource_common *common)
+static int power_rpi4_exit(void *data)
{
- if (!common)
+ hal_backend_power_funcs *funcs;
+
+ if (!data)
return -EINVAL;
- free(common);
+ funcs = (hal_backend_power_funcs *)data;
+
+ if (funcs->cpu)
+ free(funcs->cpu);
+ if (funcs->memory)
+ free(funcs->memory);
+
+ free(funcs);
return 0;
}
-HAL_MODULE_STRUCTURE = {
- .magic = HAL_INFO_TAG,
- .id = PASS_RESOURCE_CPU_ID,
- .name = PASS_RESOURCE_CPU_NAME,
- .open = standard_cpu_open,
- .close = standard_cpu_close,
+hal_backend hal_backend_power_data = {
+ .name = "power-rpi4",
+ .vendor = "Rasberry Pi",
+ .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
+ .init = power_rpi4_init,
+ .exit = power_rpi4_exit,
};
+++ /dev/null
-/*
- * PASS (Power Aware System Service)
- *
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <pass/hal.h>
-#include <pass/hal-log.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "../shared/sysfs.h"
-
-#define FAULT_AROUND_BYTES_PATH "/sys/kernel/debug/fault_around_bytes"
-
-static int rpi_memory_get_fault_around_bytes(char *res_name)
-{
- int ret, fault_around_bytes;
-
- if (!res_name)
- return -EINVAL;
-
- ret = sysfs_read_int(FAULT_AROUND_BYTES_PATH, &fault_around_bytes);
- if (ret < 0)
- return ret;
-
- return fault_around_bytes;
-}
-
-static int rpi_memory_set_fault_around_bytes(char *res_name,
- int fault_around_bytes)
-{
- int ret;
-
- if ((!res_name) || (fault_around_bytes <= 0))
- return -EINVAL;
-
- ret = sysfs_write_int(FAULT_AROUND_BYTES_PATH, fault_around_bytes);
- if (ret < 0)
- return ret;
-
- return 0;
-}
-
-static int rpi_memory_open(char *res_name, struct pass_resource_info *info,
- struct pass_resource_common **common)
-{
- struct pass_resource_memory *res;
-
- if (!info)
- return -EINVAL;
-
- res = calloc(1, sizeof(struct pass_resource_memory));
- if (!res)
- return -ENOMEM;
-
- res->common.info = info;
- res->get_fault_around_bytes = rpi_memory_get_fault_around_bytes;
- res->set_fault_around_bytes = rpi_memory_set_fault_around_bytes;
-
- *common = (struct pass_resource_common *)res;
-
- return 0;
-}
-
-static int rpi_memory_close(char *res_name, struct pass_resource_common *common)
-{
- if (!common)
- return -EINVAL;
-
- free(common);
-
- return 0;
-}
-
-HAL_MODULE_STRUCTURE = {
- .magic = HAL_INFO_TAG,
- .id = PASS_RESOURCE_MEMORY_ID,
- .name = PASS_RESOURCE_MEMORY_NAME,
- .open = rpi_memory_open,
- .close = rpi_memory_close,
-};