--- /dev/null
+#include <errno.h>
+#include <limits.h>
+#include <pass/hal.h>
+#include <pass/hal-log.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../shared/sysfs.h"
+
+/* TODO: Version! */
+#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_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_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];
+ int ret;
+
+ if ((!res_name) || (!governor))
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%s%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);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int tm2_dvfs_set_curr_governor(char *res_name, char *governor)
+{
+ char path[PATH_MAX];
+ int ret;
+
+ if ((!res_name) || (!governor))
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%s%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);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int tm2_dvfs_get_curr_freq(char *res_name)
+{
+ char path[PATH_MAX];
+ int freq, ret;
+
+ if (!res_name)
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%s%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);
+ if (ret < 0)
+ return ret;
+
+ return freq;
+}
+
+static int tm2_dvfs_get_min_freq(char *res_name)
+{
+ char path[PATH_MAX];
+ int freq, ret;
+
+ if (!res_name)
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%s%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);
+ if (ret < 0)
+ return ret;
+
+ return freq;
+}
+
+static int tm2_dvfs_set_min_freq(char *res_name, int freq)
+{
+ char path[PATH_MAX];
+ int ret;
+
+ if ((!res_name) || (freq < 0))
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%s%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);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int tm2_dvfs_get_max_freq(char *res_name)
+{
+ char path[PATH_MAX];
+ int freq, ret;
+
+ if (!res_name)
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%s%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);
+ if (ret < 0)
+ return ret;
+
+ return freq;
+}
+
+static int tm2_dvfs_set_max_freq(char *res_name, int freq)
+{
+ char path[PATH_MAX];
+ int ret;
+
+ if ((!res_name) || (freq < 0))
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%s%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);
+ if (ret < 0)
+ return ret;
+ return 0;
+}
+
+
+static struct pass_resource_dvfs_ops tm2_gpu_dvfs_ops = {
+ .get_curr_governor = tm2_dvfs_get_curr_governor,
+ .set_curr_governor = tm2_dvfs_set_curr_governor,
+ .get_avail_governor = NULL,
+ .get_curr_freq = tm2_dvfs_get_curr_freq,
+ .get_min_freq = tm2_dvfs_get_min_freq,
+ .set_min_freq = tm2_dvfs_set_min_freq,
+ .get_max_freq = tm2_dvfs_get_max_freq,
+ .set_max_freq = tm2_dvfs_set_max_freq,
+ .get_up_threshold = NULL,
+ .set_up_threshold = NULL,
+ .get_load_table = NULL,
+};
+
+static int tm2_tmu_get_temp(char *res_name)
+{
+ char path[PATH_MAX];
+ int temp;
+ int ret;
+
+ if (!res_name)
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%d%s",
+ TMU_PATH_PREFIX,
+ TM2_GPU_THERMAL_ZONE_NUM,
+ TMU_TEMP_PATH_SUFFIX);
+
+ ret = sysfs_read_int(path, &temp);
+ if (ret < 0)
+ return ret;
+
+ return temp;
+}
+
+static int tm2_tmu_get_policy(char *res_name, char *policy)
+{
+ char path[PATH_MAX];
+ int ret;
+
+ if ((!res_name) || (!policy))
+ return -EINVAL;
+
+ snprintf(path, PATH_MAX, "%s%d%s",
+ TMU_PATH_PREFIX,
+ TM2_GPU_THERMAL_ZONE_NUM,
+ TMU_POLICY_PATH_SUFFIX);
+
+ ret = sysfs_read_str(path, policy, BUFF_MAX);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static struct pass_resource_tmu_ops tm2_gpu_tmu_ops = {
+ .get_temp = tm2_tmu_get_temp,
+ .get_policy = tm2_tmu_get_policy,
+};
+
+static int tm2_gpu_open(struct pass_resource_info *info,
+ struct pass_resource_common **common)
+{
+ struct pass_resource_gpu *gpu_res;
+
+ if (!info)
+ return -EINVAL;
+
+ /* TODO: Possibility of a memory leak */
+ gpu_res = calloc(1, sizeof(struct pass_resource_gpu));
+ if (!gpu_res)
+ return -ENOMEM;
+
+ gpu_res->common.info = info;
+ gpu_res->dvfs = tm2_gpu_dvfs_ops;
+ gpu_res->tmu = tm2_gpu_tmu_ops;
+
+ *common = (struct pass_resource_common *) gpu_res;
+
+ return 0;
+}
+
+static int tm2_gpu_close(struct pass_resource_common *common)
+{
+ if (!common)
+ return -EINVAL;
+
+ free(common);
+
+ return 0;
+}
+
+HAL_MODULE_STRUCTURE = {
+ .magic = HAL_INFO_TAG,
+ .hal_version = HAL_VERSION,
+ .device_version = DEV_VERSION_GPU,
+ .id = PASS_RESOURCE_GPU_ID,
+ .name = PASS_RESOURCE_GPU_NAME,
+ .author = "Wook Song <wook16.song@samsung.com>",
+ .open = tm2_gpu_open,
+ .close = tm2_gpu_close,
+};