+++ /dev/null
-/*
- * Copyright (c) 2017 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.
- */
-
-#ifndef _PASS_HAL_H_
-#define _PASS_HAL_H_
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-#define BUFF_MAX 255
-
-#define MAKE_4B_CODE_4(A, B, C, D) \
- ((((A) & 0xff) << 24) | (((B) & 0xff) << 16) | \
- (((C) & 0xff) << 8) | (((D) & 0xff)))
-#define MAKE_TAG_CONSTANT(A, B, C, D) MAKE_4B_CODE_4(A, B, C, D)
-
-#define HAL_INFO_TAG MAKE_TAG_CONSTANT('P', 'A', 'S', 'S')
-
-/* Symbolic name of the HAL info (PASS HAL Info) */
-#define HAL_INFO_SYM PassHalInfo
-
-#define PASS_RESOURCE_UNKNOWN 0
-#define PASS_RESOURCE_CPU_ID 1
-#define PASS_RESOURCE_BUS_ID 2
-#define PASS_RESOURCE_GPU_ID 3
-#define PASS_RESOURCE_MEMORY_ID 4
-#define PASS_RESOURCE_NONSTANDARD_ID 99
-
-#define PASS_RESOURCE_CPU_NAME "cpu"
-#define PASS_RESOURCE_BUS_NAME "bus"
-#define PASS_RESOURCE_GPU_NAME "gpu"
-#define PASS_RESOURCE_MEMORY_NAME "memory"
-#define PASS_RESOURCE_NONSTANDARD_NAME "nonstandard"
-
-/**
- * Define the common structure
- */
-
-struct pass_resource_common;
-
-/*
- * pass_resource_info - Define the information structure for the resource.
- *
- * @magic : magic must be initialized to HAL_INFO_TAG
- * @hal_version : HAL version
- * @device_version: device version
- * @id : device id, can have the following value.
- * - PASS_RESOURCE_CPU_ID
- * - PASS_RESOURCE_BUS_ID
- * - PASS_RESOURCE_GPU_ID
- * - PASS_RESOURCE_MEMORY_ID
- * - PASS_RESOURCE_NONSTANDARD_ID
- * @name : device name, can have the following value.
- * - PASS_RESOURCE_CPU_NAME
- * - PASS_RESOURCE_BUS_NAME
- * - PASS_RESOURCE_GPU_NAME
- * - PASS_RESOURCE_MEMORY_NAME
- * - PASS_RESOURCE_NONSTANDARD_NAME
- * @dso : module's dso
- * @resourced[] : reserved for future use
- * @open : function pointer to open device
- * @close : function pointer to close device
- */
-struct pass_resource_info {
- uint32_t magic;
- uint16_t hal_version;
- uint16_t device_version;
- const int id;
- const char *name;
- void *dso;
- uint32_t reserved[8];
-
- int (*open)(char *res_name, struct pass_resource_info *info,
- struct pass_resource_common **common);
- int (*close)(char *res_name, struct pass_resource_common *common);
-};
-
-struct pass_resource_common {
- /* indicate to this device information structure */
- struct pass_resource_info *info;
-};
-
-/*
- * Define the ops (operations) structure which are used on specific resource.
- */
-struct pass_resource_dvfs_ops {
- /* Get and set the current governor. */
- int (*get_curr_governor)(char *res_name, char *governor);
- int (*set_curr_governor)(char *res_name, char *governor);
-
- int (*get_avail_governor)(char *res_name, char **avail_governor);
-
- /* Get the current frequency. */
- int (*get_curr_freq)(char *res_name);
-
- /* Get and set the minimum frequency. */
- int (*get_min_freq)(char *res_name);
- int (*set_min_freq)(char *res_name, int freq);
-
- /* Get and set the maximum frequency. */
- int (*get_max_freq)(char *res_name);
- int (*set_max_freq)(char *res_name, int freq);
-
- /* Get the minimum/maximum frequency which can be set to resource. */
- int (*get_available_min_freq)(char *res_name);
- int (*get_available_max_freq)(char *res_name);
-
- /* Get and set the up_threshold to support boosting. */
- int (*get_up_threshold)(char *res_name);
- int (*set_up_threshold)(char *res_name, int up_threshold);
-
- /* Get the load_table of each resource to estimate the system load. */
- int (*get_load_table)(char *name, void *pass_cpu_load_table);
-};
-
-struct pass_resource_hotplug_ops {
- /* Get and set the online status of resource. */
- int (*get_online_state)(char *res_name, int cpu);
- int (*set_online_state)(char *res_name, int cpu, int on);
- /* Get and set the minimum number of online CPUs */
- int (*get_online_min_num) (char *res_name);
- int (*set_online_min_num) (char *res_name, int min_num);
- /* Get and set the maximum number of online CPUs */
- int (*get_online_max_num) (char *res_name);
- int (*set_online_max_num) (char *res_name, int max_num);
-};
-
-struct pass_resource_tmu_ops {
- /* Get the current temperature of resource. */
- int (*get_temp)(char *res_thermal_name);
-
- /* Get the policy of thermal management unit. */
- int (*get_policy)(char *res_thermal_name, char *policy);
-};
-
-/*
- * Define the resource structure for CPU H/W.
- *
- * @common : common resource structure.
- * @dvfs : function lists for the DVFS (Dynamic Volt. & Freq. Scaling).
- * @tmu : function lists for the TMU (Thermal Management Unit).
- * @hotplug : function lists for the CPU on/off.
- */
-struct pass_resource_cpu {
- struct pass_resource_common common;
-
- struct pass_resource_dvfs_ops dvfs;
- struct pass_resource_tmu_ops tmu;
- struct pass_resource_hotplug_ops hotplug;
-};
-
-/*
- * Define the resource structure for Memory Bus H/W.
- *
- * @common : common resource structure.
- * @dvfs : function lists for the DVFS (Dynamic Volt. & Freq. Scaling).
- * @tmu : function lists for the TMU (Thermal Management Unit).
- */
-struct pass_resource_bus {
- struct pass_resource_common common;
-
- struct pass_resource_dvfs_ops dvfs;
- struct pass_resource_tmu_ops tmu;
-};
-
-/*
- * Define the resource structure for GPU H/W.
- *
- * @common : common resource structure.
- * @dvfs : function lists for the DVFS (Dynamic Volt. & Freq. Scaling).
- * @tmu : function lists for the TMU (Thermal Management Unit).
- */
-struct pass_resource_gpu {
- struct pass_resource_common common;
-
- struct pass_resource_dvfs_ops dvfs;
- struct pass_resource_tmu_ops tmu;
-};
-
-/*
- * Define the resource structure for Memory H/W.
- *
- * @common : common resource structure.
- */
-struct pass_resource_memory {
- struct pass_resource_common common;
-
- /* Get and set the /sys/kernel/debug/fault_around_bytes */
- int (*get_fault_around_bytes)(char *res_name);
- int (*set_fault_around_bytes)(char *res_name, int fault_around_bytes);
-};
-
-/*
- * Define the resource structure for nonstandard H/W.
- *
- * Following function is Deprecated. (Not recommended for use)
- * @set_pmqos_data : function to bypass the scenario data to HAL.
- *
- * This structure indicates the nonstandard H/W which doesn't have
- * the official supported framework (e.g., cpufreq, devfreq and so on)
- * in Linux Kernel. But, the specific device might be controlled
- * according to PMQoS scenario or other cases.
- */
-struct pass_resource_nonstandard {
- struct pass_resource_common common;
-
- /*
- * NOTE: It is not propper method. But PASS must need to keep
- * the backwards compatibility, set the PMQoS's data from
- * platform to hal. So, It is not recommended to use it.
- *
- * This function will be removed after finding the proper method.
- */
- int (*set_pmqos_data)(char *res_name, void *data);
-};
-
-int pass_get_hal_info(const char *id, const struct pass_resource_info **info);
-
-/**
- * Structure define of HAL info module
- *
- * All HAL module should be use below define to make a specific
- * structure for Tizen HAL. pass_get_resource_info function
- * will load a pass_resource_data structure by using TizenHwInfo name
- * at runtime. TizenHwInfo means Tizen Hardware Info.
- */
-#define HAL_MODULE_STRUCTURE \
- __attribute__ ((visibility("default"))) \
- struct pass_resource_info HAL_INFO_SYM
-
-#endif /* _PASS_HAL_H_ */
#include "pass.h"
#include "pass-hal.h"
-static struct pass_resource_dvfs_ops *get_dvfs(struct pass_resource *res,
- int res_type)
-{
- struct pass_resource_dvfs_ops *dvfs = NULL;
-
- switch (res_type) {
- case PASS_RESOURCE_CPU_ID:
- dvfs = &(res->hal.cpu->dvfs);
- break;
- case PASS_RESOURCE_BUS_ID:
- dvfs = &(res->hal.bus->dvfs);
- break;
- case PASS_RESOURCE_GPU_ID:
- dvfs = &(res->hal.gpu->dvfs);
- break;
- }
-
- return dvfs;
-}
-
-static struct pass_resource_tmu_ops *get_tmu(struct pass_resource *res,
- int res_type)
-{
- struct pass_resource_tmu_ops *tmu = NULL;
-
- switch (res_type) {
- case PASS_RESOURCE_CPU_ID:
- tmu = &(res->hal.cpu->tmu);
- break;
- case PASS_RESOURCE_BUS_ID:
- tmu = &(res->hal.bus->tmu);
- break;
- case PASS_RESOURCE_GPU_ID:
- tmu = &(res->hal.gpu->tmu);
- break;
- }
-
- return tmu;
-}
-
-static struct pass_resource_hotplug_ops *get_hotplug(struct pass_resource *res,
- int res_type)
-{
- struct pass_resource_hotplug_ops *hotplug = NULL;
-
- switch (res_type) {
- case PASS_RESOURCE_CPU_ID:
- hotplug = &(res->hal.cpu->hotplug);
- break;
- case PASS_RESOURCE_BUS_ID:
- case PASS_RESOURCE_GPU_ID:
- hotplug = NULL;
- break;
- }
-
- return hotplug;
-}
-
/**
* @brief Get the current governor for DVFS(Dynamic Voltage and Frequency
* Scaling) resource
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_curr_governor(struct pass_resource *res, char *governor)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res || !governor)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->get_curr_governor)
- return -ENODEV;
-
- return dvfs->get_curr_governor(res->config_data.res_name, governor);
+ return hal_power_dvfs_get_curr_governor(res->config_data.res_type,
+ res->config_data.res_name,
+ governor);
}
/**
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_curr_governor(struct pass_resource *res, char *governor)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res || !governor)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->set_curr_governor)
- return -ENODEV;
-
- return dvfs->set_curr_governor(res->config_data.res_name, governor);
+ return hal_power_dvfs_set_curr_governor(res->config_data.res_type,
+ res->config_data.res_name,
+ governor);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_curr_freq(struct pass_resource *res)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->get_curr_freq)
- return -ENODEV;
-
- return dvfs->get_curr_freq(res->config_data.res_name);
+ return hal_power_dvfs_get_curr_freq(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_min_freq(struct pass_resource *res)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->get_min_freq)
- return -ENODEV;
-
- return dvfs->get_min_freq(res->config_data.res_name);
+ return hal_power_dvfs_get_min_freq(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_min_freq(struct pass_resource *res, int freq)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res || freq < 0)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->set_min_freq)
- return -ENODEV;
-
- return dvfs->set_min_freq(res->config_data.res_name, freq);
+ return hal_power_dvfs_set_min_freq(res->config_data.res_type,
+ res->config_data.res_name,
+ freq);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_max_freq(struct pass_resource *res)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->get_max_freq)
- return -ENODEV;
-
- return dvfs->get_max_freq(res->config_data.res_name);
+ return hal_power_dvfs_get_max_freq(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_max_freq(struct pass_resource *res, int freq)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res || freq < 0)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->set_max_freq)
- return -ENODEV;
-
- return dvfs->set_max_freq(res->config_data.res_name, freq);
+ return hal_power_dvfs_set_max_freq(res->config_data.res_type,
+ res->config_data.res_name,
+ freq);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_available_min_freq(struct pass_resource *res)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->get_available_min_freq)
- return -ENODEV;
-
- return dvfs->get_available_min_freq(res->config_data.res_name);
+ return hal_power_dvfs_get_available_min_freq(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_available_max_freq(struct pass_resource *res)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->get_available_max_freq)
- return -ENODEV;
-
- return dvfs->get_available_max_freq(res->config_data.res_name);
+ return hal_power_dvfs_get_available_max_freq(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_up_threshold(struct pass_resource *res)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->get_up_threshold)
- return -ENODEV;
-
- return dvfs->get_up_threshold(res->config_data.res_name);
+ return hal_power_dvfs_get_up_threshold(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_up_threshold(struct pass_resource *res, int up_threshold)
{
- struct pass_resource_dvfs_ops *dvfs;
-
if (!res || up_threshold < 0)
return -EINVAL;
- dvfs = get_dvfs(res, res->config_data.res_type);
- if (!dvfs)
- return -EPERM;
-
- if (!dvfs->set_up_threshold)
- return -ENODEV;
-
- return dvfs->set_up_threshold(res->config_data.res_name, up_threshold);
+ return hal_power_dvfs_set_up_threshold(res->config_data.res_type,
+ res->config_data.res_name,
+ up_threshold);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_online_state(struct pass_resource *res, int cpu)
{
- struct pass_resource_hotplug_ops *hotplug;
-
if (!res || cpu < 0)
return -EINVAL;
- hotplug = get_hotplug(res, res->config_data.res_type);
- if (!hotplug)
- return -EPERM;
-
- if (!hotplug->get_online_state)
- return -ENODEV;
-
- return hotplug->get_online_state(res->config_data.res_name, cpu);
+ return hal_power_hotplug_get_online_state(res->config_data.res_type,
+ res->config_data.res_name,
+ cpu);
}
/**
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_online_state(struct pass_resource *res, int cpu, int on)
{
- struct pass_resource_hotplug_ops *hotplug;
-
if (!res || cpu < 0 || on < 0)
return -EINVAL;
- hotplug = get_hotplug(res, res->config_data.res_type);
- if (!hotplug)
- return -EPERM;
-
- if (!hotplug->set_online_state)
- return -ENODEV;
-
- return hotplug->set_online_state(res->config_data.res_name, cpu, on);
+ return hal_power_hotplug_set_online_state(res->config_data.res_type,
+ res->config_data.res_name,
+ cpu, on);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_online_min_num(struct pass_resource *res)
{
- struct pass_resource_hotplug_ops *hotplug;
-
if (!res)
return -EINVAL;
- hotplug = get_hotplug(res, res->config_data.res_type);
- if (!hotplug)
- return -EPERM;
-
- if (!hotplug->get_online_min_num)
- return -ENODEV;
-
- return hotplug->get_online_min_num(res->config_data.res_name);
+ return hal_power_hotplug_get_online_min_num(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_online_min_num(struct pass_resource *res, int num)
{
- struct pass_resource_hotplug_ops *hotplug;
-
if ((!res) || (num < 0))
return -EINVAL;
- hotplug = get_hotplug(res, res->config_data.res_type);
- if (!hotplug)
- return -EPERM;
-
- if (!hotplug->set_online_min_num)
- return -ENODEV;
-
- return hotplug->set_online_min_num(res->config_data.res_name, num);
+ return hal_power_hotplug_set_online_min_num(res->config_data.res_type,
+ res->config_data.res_name,
+ num);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_online_max_num(struct pass_resource *res)
{
- struct pass_resource_hotplug_ops *hotplug;
-
if (!res)
return -EINVAL;
- hotplug = get_hotplug(res, res->config_data.res_type);
- if (!hotplug)
- return -EPERM;
-
- if (!hotplug->get_online_max_num)
- return -ENODEV;
-
- return hotplug->get_online_max_num(res->config_data.res_name);
+ return hal_power_hotplug_get_online_max_num(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_online_max_num(struct pass_resource *res, int num)
{
- struct pass_resource_hotplug_ops *hotplug;
-
if ((!res) || (num < 0))
return -EINVAL;
- hotplug = get_hotplug(res, res->config_data.res_type);
- if (!hotplug)
- return -EPERM;
-
- if (!hotplug->set_online_max_num)
- return -ENODEV;
-
- return hotplug->set_online_max_num(res->config_data.res_name, num);
+ return hal_power_hotplug_set_online_max_num(res->config_data.res_type,
+ res->config_data.res_name,
+ num);
}
/**
* @return @c integer (both positive and negative are possible) on success
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_temp(struct pass_resource *res)
{
- struct pass_resource_tmu_ops *tmu;
-
if (!res)
return -EINVAL;
- tmu = get_tmu(res, res->config_data.res_type);
- if (!tmu)
- return -EPERM;
-
- if (!tmu->get_temp)
- return -ENODEV;
-
/*
* In the case of the HAL TMU ops, res_thermal_name is used
* as the first argument instead of res_name.
*/
- return tmu->get_temp(res->config_data.res_thermal_name);
+ return hal_power_thermal_get_temp(res->config_data.res_type,
+ res->config_data.res_thermal_name);
}
/**
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_tmu_policy(struct pass_resource *res, char *policy)
{
- struct pass_resource_tmu_ops *tmu;
-
if (!res || !policy)
return -EINVAL;
- tmu = get_tmu(res, res->config_data.res_type);
- if (!tmu)
- return -EPERM;
-
- if (!tmu->get_policy)
- return -ENODEV;
-
/*
* In the case of the HAL TMU ops, res_thermal_name is used
* as the first argument instead of res_name.
*/
- return tmu->get_policy(res->config_data.res_thermal_name, policy);
+ return hal_power_thermal_get_policy(res->config_data.res_type,
+ res->config_data.res_thermal_name,
+ policy);
}
/**
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_fault_around_bytes(struct pass_resource *res,
int fault_around_bytes)
{
- struct pass_resource_memory *memory;
-
if (!res)
return -EINVAL;
- switch (res->config_data.res_type) {
- case PASS_RESOURCE_MEMORY_ID:
- memory = res->hal.memory;
- break;
- default:
- return -EPERM;
- }
-
- if (!memory->set_fault_around_bytes)
- return -ENODEV;
-
- return memory->set_fault_around_bytes(res->config_data.res_name, fault_around_bytes);
+ return hal_power_memory_set_fault_around_bytes(res->config_data.res_type,
+ res->config_data.res_name,
+ fault_around_bytes);
}
/**
* @return @c positive integer on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_get_fault_around_bytes(struct pass_resource *res)
{
- struct pass_resource_memory *memory;
-
if (!res)
return -EINVAL;
- switch (res->config_data.res_type) {
- case PASS_RESOURCE_MEMORY_ID:
- memory = res->hal.memory;
- break;
- default:
- return -EPERM;
- }
-
- if (!memory->get_fault_around_bytes)
- return -ENODEV;
-
- return memory->get_fault_around_bytes(res->config_data.res_name);
+ return hal_power_memory_get_fault_around_bytes(res->config_data.res_type,
+ res->config_data.res_name);
}
/**
* @return @c 0 on success, otherwise error value
* @retval -22 Invalid argument (-EINVAL)
* @retval -1 Operation not permitted (-EPERM)
- * @retval -19 Operation not supported (-ENODEV)
+ * @retval -19 Operation not supported (-ENOTSUP)
*/
int pass_hal_set_pmqos_data(struct pass_resource *res, void *data)
{
- struct pass_resource_nonstandard *nonstandard = NULL;
-
if (!res || !data)
return -EINVAL;
- switch (res->config_data.res_type) {
- case PASS_RESOURCE_NONSTANDARD_ID:
- nonstandard = (res->hal.nonstandard);
- break;
- default:
- return -EPERM;
- }
-
- if (!nonstandard->set_pmqos_data)
- return -ENODEV;
-
- return nonstandard->set_pmqos_data(res->config_data.res_name, data);
+ return hal_power_misc_set_pmqos_data(res->config_data.res_type,
+ res->config_data.res_name, data);
}
/**
*/
int pass_hal_get_resource(struct pass_resource *res)
{
- struct pass_resource_info *info;
- const char *name;
- int ret;
-
if (!res)
return -EINVAL;
- switch (res->config_data.res_type) {
- case PASS_RESOURCE_CPU_ID:
- name = PASS_RESOURCE_CPU_NAME;
- break;
- case PASS_RESOURCE_BUS_ID:
- name = PASS_RESOURCE_BUS_NAME;
- break;
- case PASS_RESOURCE_GPU_ID:
- name = PASS_RESOURCE_GPU_NAME;
- break;
- case PASS_RESOURCE_MEMORY_ID:
- name = PASS_RESOURCE_MEMORY_NAME;
- break;
- case PASS_RESOURCE_NONSTANDARD_ID:
- name = PASS_RESOURCE_NONSTANDARD_NAME;
- break;
- default:
- _E("Unsupported resource type (type: %d)\n",
- res->config_data.res_type);
- return -EINVAL;
- };
-
- ret = pass_get_hal_info(name,
- (const struct pass_resource_info **)&info);
- if (ret < 0) {
- _E("Failed to get %s.so for '%s' resource\n",
- name, res->config_data.res_name);
- return -EINVAL;
- }
-
- if (!info->open || !info->close) {
- _E("Failed to get functions of %s.so for '%s' resource\n",
- name, res->config_data.res_name);
- return -EPERM;
- }
-
- switch (res->config_data.res_type) {
- case PASS_RESOURCE_CPU_ID:
- ret = info->open(res->config_data.res_name, info,
- (struct pass_resource_common**)&res->hal.cpu);
- break;
- case PASS_RESOURCE_BUS_ID:
- ret = info->open(res->config_data.res_name, info,
- (struct pass_resource_common**)&res->hal.bus);
- break;
- case PASS_RESOURCE_GPU_ID:
- ret = info->open(res->config_data.res_name, info,
- (struct pass_resource_common**)&res->hal.gpu);
- break;
- case PASS_RESOURCE_MEMORY_ID:
- ret = info->open(res->config_data.res_name, info,
- (struct pass_resource_common**)&res->hal.memory);
- break;
- case PASS_RESOURCE_NONSTANDARD_ID:
- ret = info->open(res->config_data.res_name, info,
- (struct pass_resource_common**)&res->hal.nonstandard);
- break;
- };
-
- if (ret < 0) {
- _E("Failed to open %s.so for '%s' resource\n",
- name, res->config_data.res_name);
- return -EINVAL;
- }
-
- return 0;
+ return hal_power_get_backend(res->config_data.res_type);
}
/**
*/
int pass_hal_put_resource(struct pass_resource *res)
{
- struct pass_resource_common *common;
- struct pass_resource_info *info;
- int ret;
-
if (!res)
return -EINVAL;
- switch (res->config_data.res_type) {
- case PASS_RESOURCE_CPU_ID:
- common = (struct pass_resource_common*)res->hal.cpu;
- info = res->hal.cpu->common.info;
- ret = info->close(res->config_data.res_name, common);
- break;
- case PASS_RESOURCE_BUS_ID:
- common = (struct pass_resource_common*)res->hal.bus;
- info = res->hal.bus->common.info;
- ret = info->close(res->config_data.res_name, common);
- break;
- case PASS_RESOURCE_GPU_ID:
- common = (struct pass_resource_common*)res->hal.gpu;
- info = res->hal.gpu->common.info;
- ret = info->close(res->config_data.res_name, common);
- break;
- case PASS_RESOURCE_MEMORY_ID:
- common = (struct pass_resource_common*)res->hal.memory;
- info = res->hal.memory->common.info;
- ret = info->close(res->config_data.res_name, common);
- break;
- case PASS_RESOURCE_NONSTANDARD_ID:
- common = (struct pass_resource_common*)res->hal.nonstandard;
- info = res->hal.nonstandard->common.info;
- ret = info->close(res->config_data.res_name, common);
- break;
- default:
- return -EINVAL;
- };
-
- if (ret < 0) {
- _E("Failed to close %s.so for '%s' resource\n",
- info->name, res->config_data.res_name);
- return -EINVAL;
- }
-
- return 0;
+ return hal_power_put_backend();
}