From 8b8ee36a11fd294f9768bb4fa4250d37970c3a6f Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 23 Jan 2017 10:22:40 +0900 Subject: [PATCH] pass: hal: Add new hal interface to handle the h/w resource The pass handle the h/w resources such as CPU, Memory Bus and GPU. This patch adds the new HAL (Hardware Abstract Layer) interface to support the pass on all h/w boards. This patch defines the three type of resources. - struct pass_resrouce_cpu for CPU h/w. - struct pass_resrouce_bus for Memory bus h/w. - struct pass_resrouce_gpu for GPU h/w. The hal-cpu-example.c is just example to help the implementation of he real HAL. Change-Id: I09035678cdeac185a67b79492176986f5e01e23b Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 2 + src/hal/hal-cpu-example.c | 170 +++++++++++++++++++++++++++++++++++++++++ src/hal/hal.c | 89 ++++++++++++++++++++++ src/hal/hal.h | 187 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 448 insertions(+) create mode 100644 src/hal/hal-cpu-example.c create mode 100644 src/hal/hal.c create mode 100644 src/hal/hal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index dbaad06..14da2fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ SET(SRCS src/pass/pass-pmqos.c src/pmqos/pmqos.c src/pmqos/pmqos-parser.c + src/hal/hal.c src/shared/pass-systemd.c src/core/common.c src/core/config-parser.c @@ -87,6 +88,7 @@ SET(SRCS INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/pass) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/hal) SET(PKG_MODULES ecore diff --git a/src/hal/hal-cpu-example.c b/src/hal/hal-cpu-example.c new file mode 100644 index 0000000..7faaf25 --- /dev/null +++ b/src/hal/hal-cpu-example.c @@ -0,0 +1,170 @@ +/* + * PASS HAL + * + * 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 requcpued 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +static int get_curr_governor(char *res_name, char *governor) +{ + /* TODO */ + return 0; +} + +static int set_curr_governor(char *res_name, char *governor) +{ + /* TODO */ + return 0; +} + +static int get_avail_governor(char *res_name, char **avail_governor) +{ + /* TODO */ + return 0; +} + +static int get_curr_freq(char *res_name) +{ + /* TODO */ + return 0; +} + +static int get_min_freq(char *res_name) +{ + /* TODO */ + return 0; +} + +static int set_min_freq(char *res_name, int freq) +{ + /* TODO */ + return 0; +} + +static int get_max_freq(char *res_name) +{ + /* TODO */ + return 0; +} + +static int set_max_freq(char *res_name, int freq) +{ + /* TODO */ + return 0; +} + +static int get_up_threshold(char *res_name) +{ + /* TODO */ + return 0; +} + +static int set_up_threshold(char *res_name, int up_threshold) +{ + /* TODO */ + return 0; +} + +static int get_online_state(char *res_name, int cpu) +{ + /* TODO */ + return 0; +} + +static int set_online_state(char *res_name, int cpu, int on) +{ + /* TODO */ + return 0; +} + +static int get_tmu_temp(char *res_name) +{ + /* TODO */ + return 0; +} + +static int get_tmu_policy(char *res_name, char *policy) +{ + /* TODO */ + return 0; +} + +static int pass_open(struct pass_resource_info *info, + struct pass_resource_common **common) +{ + struct pass_resource_cpu *res; + + if (!info || !common) + return -EINVAL; + + res = calloc(1, sizeof(*res)); + if (!res) + return -ENOMEM; + + res->common.info = info; + + res->dvfs.get_curr_governor = get_curr_governor; + res->dvfs.set_curr_governor = set_curr_governor; + res->dvfs.get_avail_governor = get_avail_governor; + res->dvfs.get_curr_freq = get_curr_freq; + res->dvfs.get_min_freq = get_min_freq; + res->dvfs.set_min_freq = set_min_freq; + res->dvfs.get_max_freq = get_max_freq; + res->dvfs.set_max_freq = set_max_freq; + res->dvfs.get_up_threshold = get_up_threshold; + res->dvfs.set_up_threshold = set_up_threshold; + + res->tmu.get_temp = get_tmu_temp; + res->tmu.get_policy = get_tmu_policy; + + res->hotplug.get_online_state = get_online_state; + res->hotplug.set_online_state = set_online_state; + + *common = (struct pass_resource_common *)res; + return 0; +} + +static int pass_close(struct pass_resource_common *common) +{ + if (!common) + return -EINVAL; + + free(common); + return 0; +} + +HARDWARE_MODULE_STRUCTURE = { + .magic = HARDWARE_INFO_TAG, + .hal_version = HARDWARE_INFO_VERSION, + .device_version = HARDWARE_INFO_VERSION_CPU, + .id = PASS_RESOURCE_CPU_ID, + .name = PASS_RESOURCE_CPU_NAME, + .open = pass_open, + .close = pass_close, +}; diff --git a/src/hal/hal.c b/src/hal/hal.c new file mode 100644 index 0000000..3988a42 --- /dev/null +++ b/src/hal/hal.c @@ -0,0 +1,89 @@ +/* + * PASS (Power Aware System Service) HAL + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "hal.h" +#include "shared/log-macro.h" + +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility("default"))) +#endif + +#ifndef LIBPATH +#error LIBPATH is not defined. +#endif + +#define MODULE_PATH LIBPATH"/pass" + +#define STRINGIZE2(s) #s +#define STRINGIZE(s) STRINGIZE2(s) + +EXPORT +int pass_get_hw_info(const char *name, const struct pass_resource_info **info) +{ + char path[PATH_MAX]; + void *handle; + struct pass_resource_info *it; + + if (!info || !name) + return -EINVAL; + + /* Find matched module path */ + snprintf(path, sizeof(path), "%s/%s.so", MODULE_PATH, name); + if (access(path, R_OK) != 0) { + _E("there is no %s device", name); + return -ENODEV; + } + + /* Load module */ + handle = dlopen(path, RTLD_NOW); + if (!handle) { + _E("fail to open module : %s", dlerror()); + goto error; + } + + it = dlsym(handle, STRINGIZE(HARDWARE_INFO_SYM)); + if (!it) { + _E("fail to find symbol : %s", dlerror()); + goto error; + } + + /* Check id */ + if (strncmp(name, it->name, strlen(name)) != 0) { + _E("fail to match name : name(%s), it->name(%s)", name, + it->name); + goto error; + } + + it->dso = handle; + *info = it; + return 0; + +error: + if (handle) + dlclose(handle); + + return -ENOENT; +} diff --git a/src/hal/hal.h b/src/hal/hal.h new file mode 100644 index 0000000..f41c622 --- /dev/null +++ b/src/hal/hal.h @@ -0,0 +1,187 @@ +/* + * 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 +#include + + +#define MAKE_TAG_CONSTANT(A,B,C,D) \ + (((A) << 24) | ((B) << 16) | ((C) << 8) | (D)) +#define HARDWARE_INFO_TAG MAKE_TAG_CONSTANT('T','H','I','T') +#define MAKE_VERSION(maj,min) ((((maj) & 0xff) << 8) | ((min) & 0xff)) + +/* Version of the struct pass_hw_info */ +#define HARDWARE_INFO_VERSION MAKE_VERSION(0,1) + +#define HARDWARE_INFO_VERSION_CPU MAKE_VERSION(0,1) +#define HARDWARE_INFO_VERSION_BUS MAKE_VERSION(0,1) +#define HARDWARE_INFO_VERSION_GPU MAKE_VERSION(0,1) + +/* Name of the hardware info symbolic (Tizen Hardware Info) */ +#define HARDWARE_INFO_SYM TizenHwInfo + +#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_CPU_NAME "cpu" +#define PASS_RESOURCE_BUS_NAME "bus" +#define PASS_RESOURCE_GPU_NAME "gpu" + +/** + * Define the common structure + */ + +struct pass_resource_common; + +/* + * pass_resource_info - Define the information structure for the resource. + * + * @magic : magic must be initialized to HARDWARE_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 + * @name : device name, can have the following value. + * - PASS_RESOURCE_CPU_NAME + * - PASS_RESOURCE_BUS_NAME + * - PASS_RESOURCE_GPU_NAME + * @author : author 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; + const char *author; + void *dso; + uint32_t reserved[8]; + + int (*open)(struct pass_resource_info *info, + struct pass_resource_common **common); + int (*close)(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 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); +}; + +struct pass_resource_tmu_ops { + /* Get the current temperature of resoruce. */ + int (*get_temp)(char *res_name); + + /* Get the policy of thermal management unit. */ + int (*get_policy)(char *res_name, char *policy); +}; + + +/* + * Define the specific resource structure. + * + * @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 Dynamic Hotplug. + * + * PASS hal support following kind of h/w resources: + * - CPU, struct pass_resource_cpu + * - BUS, struct pass_resource_bus + * - GPU, struct pass_resource_gpu + */ +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; +}; + +struct pass_resource_bus { + struct pass_resource_common common; + + struct pass_resource_dvfs_ops dvfs; + struct pass_resource_tmu_ops tmu; +}; + +struct pass_resource_gpu { + struct pass_resource_common common; + + struct pass_resource_dvfs_ops dvfs; + struct pass_resource_tmu_ops tmu; +}; + +int pass_get_hw_info(const char *id, const struct pass_resource_info **info); + +/** + * Structure define of hardware info module + * + * All hardware 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 HARDWARE_MODULE_STRUCTURE \ + __attribute__ ((visibility("default"))) \ + struct pass_resource_info HARDWARE_INFO_SYM + +#endif /* _PASS_HAL_H_ */ -- 2.7.4