pass-hal: tm2: Update TMU HAL functions to use pass_res_thermal_name
[platform/adaptation/tm2/pass-hal-tm2.git] / src / gpu / gpu.c
index 28a8ffd..46b0dec 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * PASS (Power Aware System Service)
+ *
+ * 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.
+ */
 #include <errno.h>
 #include <limits.h>
 #include <pass/hal.h>
 #define HAL_VERSION    MAKE_2B_CODE_4(VER_MAJOR,VER_MINOR,VER_REVISION,VER_RELEASE)
 #define DEV_VERSION_GPU        MAKE_2B_CODE_2(1,0)
 
-#define DEVFREQ_GPU_PATH_PREFIX                        "/sys/devices/platform/soc/"
-#define DEVFREQ_GPU_PATH_INFIX                 "/devfreq/"
+#define DEVFREQ_GPU_PATH_PREFIX                        "/sys/class/devfreq/"
 #define DEVFREQ_GPU_CURR_GOVERNOR_PATH_SUFFIX  "/governor"
 #define DEVFREQ_GPU_CURR_FREQ_PATH_SUFFIX      "/cur_freq"
 #define DEVFREQ_GPU_MIN_FREQ_PATH_SUFFIX       "/min_freq"
 #define DEVFREQ_GPU_MAX_FREQ_PATH_SUFFIX       "/max_freq"
 
-#define TMU_PATH_PREFIX                                "/sys/class/thermal/thermal_zone"
+#define TMU_PATH_PREFIX                                "/sys/class/thermal/"
 #define TMU_TEMP_PATH_SUFFIX                   "/temp"
 #define TMU_POLICY_PATH_SUFFIX                 "/policy"
 
-#define TM2_GPU_THERMAL_ZONE_NUM               2
-
 static int tm2_dvfs_get_curr_governor(char *res_name, char *governor)
 {
        char path[PATH_MAX];
@@ -33,11 +47,9 @@ static int tm2_dvfs_get_curr_governor(char *res_name, char *governor)
        if ((!res_name) || (!governor))
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%s%s%s%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                DEVFREQ_GPU_PATH_PREFIX,
                res_name,
-               DEVFREQ_GPU_PATH_INFIX,
-               res_name,
                DEVFREQ_GPU_CURR_GOVERNOR_PATH_SUFFIX);
 
        ret = sysfs_read_str(path, governor, BUFF_MAX);
@@ -55,11 +67,9 @@ static int tm2_dvfs_set_curr_governor(char *res_name, char *governor)
        if ((!res_name) || (!governor))
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%s%s%s%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                DEVFREQ_GPU_PATH_PREFIX,
                res_name,
-               DEVFREQ_GPU_PATH_INFIX,
-               res_name,
                DEVFREQ_GPU_CURR_GOVERNOR_PATH_SUFFIX);
 
        ret = sysfs_write_str(path, governor);
@@ -77,11 +87,9 @@ static int tm2_dvfs_get_curr_freq(char *res_name)
        if (!res_name)
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%s%s%s%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                DEVFREQ_GPU_PATH_PREFIX,
                res_name,
-               DEVFREQ_GPU_PATH_INFIX,
-               res_name,
                DEVFREQ_GPU_CURR_FREQ_PATH_SUFFIX);
 
        ret = sysfs_read_int(path, &freq);
@@ -99,11 +107,9 @@ static int tm2_dvfs_get_min_freq(char *res_name)
        if (!res_name)
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%s%s%s%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                DEVFREQ_GPU_PATH_PREFIX,
                res_name,
-               DEVFREQ_GPU_PATH_INFIX,
-               res_name,
                DEVFREQ_GPU_MIN_FREQ_PATH_SUFFIX);
 
        ret = sysfs_read_int(path, &freq);
@@ -121,11 +127,9 @@ static int tm2_dvfs_set_min_freq(char *res_name, int freq)
        if ((!res_name) || (freq < 0))
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%s%s%s%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                DEVFREQ_GPU_PATH_PREFIX,
                res_name,
-               DEVFREQ_GPU_PATH_INFIX,
-               res_name,
                DEVFREQ_GPU_MIN_FREQ_PATH_SUFFIX);
 
        ret = sysfs_write_int(path, freq);
@@ -143,11 +147,9 @@ static int tm2_dvfs_get_max_freq(char *res_name)
        if (!res_name)
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%s%s%s%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                DEVFREQ_GPU_PATH_PREFIX,
                res_name,
-               DEVFREQ_GPU_PATH_INFIX,
-               res_name,
                DEVFREQ_GPU_MAX_FREQ_PATH_SUFFIX);
 
        ret = sysfs_read_int(path, &freq);
@@ -165,11 +167,9 @@ static int tm2_dvfs_set_max_freq(char *res_name, int freq)
        if ((!res_name) || (freq < 0))
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%s%s%s%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                DEVFREQ_GPU_PATH_PREFIX,
                res_name,
-               DEVFREQ_GPU_PATH_INFIX,
-               res_name,
                DEVFREQ_GPU_MAX_FREQ_PATH_SUFFIX);
 
        ret = sysfs_write_int(path, freq);
@@ -193,7 +193,7 @@ static struct pass_resource_dvfs_ops tm2_gpu_dvfs_ops =  {
        .get_load_table = NULL,
 };
 
-static int tm2_tmu_get_temp(char *res_name)
+static int tm2_tmu_get_temp(char *res_thermal_name);
 {
        char path[PATH_MAX];
        int temp;
@@ -202,9 +202,9 @@ static int tm2_tmu_get_temp(char *res_name)
        if (!res_name)
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%d%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                TMU_PATH_PREFIX,
-               TM2_GPU_THERMAL_ZONE_NUM,
+               res_thermal_name,
                TMU_TEMP_PATH_SUFFIX);
 
        ret = sysfs_read_int(path, &temp);
@@ -214,7 +214,7 @@ static int tm2_tmu_get_temp(char *res_name)
        return temp;
 }
 
-static int tm2_tmu_get_policy(char *res_name, char *policy)
+static int tm2_tmu_get_policy(char *res_thermal_name, char *policy)
 {
        char path[PATH_MAX];
        int ret;
@@ -222,9 +222,9 @@ static int tm2_tmu_get_policy(char *res_name, char *policy)
        if ((!res_name) || (!policy))
                return -EINVAL;
 
-       snprintf(path, PATH_MAX, "%s%d%s",
+       snprintf(path, PATH_MAX, "%s%s%s",
                TMU_PATH_PREFIX,
-               TM2_GPU_THERMAL_ZONE_NUM,
+               res_thermal_name,
                TMU_POLICY_PATH_SUFFIX);
 
        ret = sysfs_read_str(path, policy, BUFF_MAX);
@@ -239,7 +239,7 @@ static struct pass_resource_tmu_ops tm2_gpu_tmu_ops = {
        .get_policy = tm2_tmu_get_policy,
 };
 
-static int tm2_gpu_open(struct pass_resource_info *info,
+static int tm2_gpu_open(char *res_name, struct pass_resource_info *info,
                struct pass_resource_common **common)
 {
        struct pass_resource_gpu *gpu_res;
@@ -261,7 +261,7 @@ static int tm2_gpu_open(struct pass_resource_info *info,
        return 0;
 }
 
-static int tm2_gpu_close(struct pass_resource_common *common)
+static int tm2_gpu_close(char *res_name, struct pass_resource_common *common)
 {
        if (!common)
                return -EINVAL;