static int parse_scenario(struct pass_resource *res, json_object *obj,
struct pass_scenario *scenario)
{
- const char *name = NULL;
+ char name[BUFF_MAX] = {};
int support;
int target_level;
int cpuhp_min_level;
int threshold;
int timer_interval_ms;
int overridable;
+ int ret = 0;
/* Get property values */
- name = get_string_from_object(obj, "name");
- support = get_boolean_from_object(obj, "support");
- target_level= get_int_from_object(obj, "target_level");
- overridable = get_boolean_from_object(obj, "overridable");
+ ret += get_property(obj, "name", DATA_TYPE_STRING,
+ true, (void *)name);
+ ret += get_property(obj, "target_level", DATA_TYPE_INT,
+ true, (void *)&target_level);
+
+ ret += get_property(obj, "support", DATA_TYPE_BOOLEAN,
+ false, (void *)&support);
+ ret += get_property(obj, "timer_interval_ms", DATA_TYPE_INT,
+ false, (void *)&timer_interval_ms);
+ ret += get_property(obj, "overridable", DATA_TYPE_BOOLEAN,
+ false, (void *)&overridable);
/* - property for only pmqos module */
- cpuhp_min_level = get_int_from_object(obj, "cpuhp_min_level");
- cpuhp_max_level = get_int_from_object(obj, "cpuhp_max_level");
+ ret += get_property(obj, "cpuhp_min_level", DATA_TYPE_INT,
+ false, (void *)&cpuhp_min_level);
+ ret += get_property(obj, "cpuhp_max_level", DATA_TYPE_INT,
+ false, (void *)&cpuhp_max_level);
/* - property for only thermal module */
temperature = get_object_from_object(obj, "temperature");
if (temperature) {
- temp_start = get_int_from_object(temperature, "start");
- temp_end = get_int_from_object(temperature, "end");
- threshold = get_int_from_object(temperature, "threshold");
+ ret += get_property(temperature, "start", DATA_TYPE_INT,
+ true, (void *)&temp_start);
+ ret += get_property(temperature, "end", DATA_TYPE_INT,
+ true, (void *)&temp_end);
+ ret += get_property(temperature, "threshold", DATA_TYPE_INT,
+ false, (void *)&threshold);
+
/* if threshold is not presented, using temp_end as default */
if (threshold < 0)
threshold = temp_end;
temp_start = temp_end = threshold = 0;
}
- timer_interval_ms = get_int_from_object(obj, "timer_interval_ms");
-
- /* Check the mandatory property values are valid or not */
- if (!name) {
- _E("Failed to get 'name' property in scenario section\n");
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get the mandatory properties of %s resource\n",
+ res->config_data.res_name);
return -EINVAL;
- } else if (target_level < 0) {
- _E("Failed to get 'target_level' property in scenario section\n");
+ }
+
+ /* Check the validation of property value */
+ if (temp_start < 0 || temp_end < 0 || temp_end < temp_start) {
+ _E("Invalid temperature range in scenario section\n");
return -EINVAL;
- } else if (temperature) {
- if (temp_start < 0 || temp_end < 0 || temp_end < temp_start) {
- _E("Invalid temperature range in scenario section\n");
- return -EINVAL;
- } else if (threshold < temp_start || threshold > temp_end) {
- _W("Invalid thermal 'threshold', using default as range 'end'\n");
- threshold = temp_end;
- }
+ } else if (threshold < temp_start || threshold > temp_end) {
+ _W("Invalid thermal 'threshold', using default as range 'end'\n");
+ threshold = temp_end;
}
/* Initialize config_data from property values of confiugartion file */
int cooling_device_state;
int charging_status;
int charging_current_uA;
+ int ret = 0;
/* Get property values */
- level = get_int_from_object(obj, "level");
- minimum_frequency_khz = get_int_from_object(obj, "dvfs,minimum_frequency_khz");
- maximum_frequency_khz = get_int_from_object(obj, "dvfs,maximum_frequency_khz");
- number_of_minimum_cpu = get_int_from_object(obj, "hotplug,number_of_minimum_cpu");
- number_of_maximum_cpu = get_int_from_object(obj, "hotplug,number_of_maximum_cpu");
-
- num_down_cond = get_int_from_object(obj, "hotplug,num_down_cond");
- num_down_cond_freq = get_int_from_object(obj, "hotplug,num_down_cond_freq");
- num_down_cond_nr_running = get_int_from_object(obj, "hotplug,num_down_cond_nr_running");
- num_down_cond_busy_cpu = get_int_from_object(obj, "hotplug,num_down_cond_busy_cpu");
-
- num_up_cond = get_int_from_object(obj, "hotplug,num_up_cond");
- num_up_cond_freq = get_int_from_object(obj, "hotplug,num_up_cond_freq");
- num_up_cond_nr_running = get_int_from_object(obj, "hotplug,num_up_cond_nr_running");
- num_up_cond_busy_cpu = get_int_from_object(obj, "hotplug,num_up_cond_busy_cpu");
-
- num_right_cond = get_int_from_object(obj, "hotplug,num_right_cond");
- num_right_cond_freq = get_int_from_object(obj, "hotplug,num_right_cond_freq");
- num_right_cond_nr_running = get_int_from_object(obj, "hotplug,num_right_cond_nr_running");
- num_right_cond_busy_cpu = get_int_from_object(obj, "hotplug,num_right_cond_busy_cpu");
-
- num_left_cond = get_int_from_object(obj, "hotplug,num_left_cond");
- num_left_cond_freq = get_int_from_object(obj, "hotplug,num_left_cond_freq");
- num_left_cond_nr_running = get_int_from_object(obj, "hotplug,num_left_cond_nr_running");
- num_left_cond_busy_cpu = get_int_from_object(obj, "hotplug,num_left_cond_busy_cpu");
-
- governor_timeout_sec = get_double_from_object(obj, "hotplug,governor_timeout_sec");
-
- fault_around_bytes = get_int_from_object(obj, "memory,fault_around_bytes");
-
- cooling_device_state = get_int_from_object(obj, "thermal,cooling_device_state");
- charging_status = get_int_from_object(obj, "battery,charging_status");
- charging_current_uA = get_int_from_object(obj, "battery,charging_current_uA");
-
- /* Check the mandatory property values are valid or not */
- if (level < 0) {
- _E("Failed to get 'level' property in 'level_list' section\n");
+ ret += get_property(obj, "level", DATA_TYPE_INT,
+ true, (void *)&level);
+ ret += get_property(obj, "dvfs,minimum_frequency_khz", DATA_TYPE_INT,
+ false, (void *)&minimum_frequency_khz);
+ ret += get_property(obj, "dvfs,maximum_frequency_khz", DATA_TYPE_INT,
+ false, (void *)&maximum_frequency_khz);
+ ret += get_property(obj, "hotplug,number_of_minimum_cpu", DATA_TYPE_INT,
+ false, (void *)&number_of_minimum_cpu);
+ ret += get_property(obj, "hotplug,number_of_maximum_cpu", DATA_TYPE_INT,
+ false, (void *)&number_of_maximum_cpu);
+
+ ret += get_property(obj, "hotplug,num_down_cond", DATA_TYPE_INT,
+ false, (void *)&num_down_cond);
+ ret += get_property(obj, "hotplug,num_down_cond_freq", DATA_TYPE_INT,
+ false, (void *)&num_down_cond_freq);
+ ret += get_property(obj, "hotplug,num_down_cond_nr_running", DATA_TYPE_INT,
+ false, (void *)&num_down_cond_nr_running);
+ ret += get_property(obj, "hotplug,num_down_cond_busy_cpu", DATA_TYPE_INT,
+ false, (void *)&num_down_cond_busy_cpu);
+
+ ret += get_property(obj, "hotplug,num_up_cond", DATA_TYPE_INT,
+ false, (void *)&num_up_cond);
+ ret += get_property(obj, "hotplug,num_up_cond_freq", DATA_TYPE_INT,
+ false, (void *)&num_up_cond_freq);
+ ret += get_property(obj, "hotplug,num_up_cond_nr_running", DATA_TYPE_INT,
+ false, (void *)&num_up_cond_nr_running);
+ ret += get_property(obj, "hotplug,num_up_cond_busy_cpu", DATA_TYPE_INT,
+ false, (void *)&num_up_cond_busy_cpu);
+
+ ret += get_property(obj, "hotplug,num_right_cond", DATA_TYPE_INT,
+ false, (void *)&num_right_cond);
+ ret += get_property(obj, "hotplug,num_right_cond_freq", DATA_TYPE_INT,
+ false, (void *)&num_right_cond_freq);
+ ret += get_property(obj, "hotplug,num_right_cond_nr_running", DATA_TYPE_INT,
+ false, (void *)&num_right_cond_nr_running);
+ ret += get_property(obj, "hotplug,num_right_cond_busy_cpu", DATA_TYPE_INT,
+ false, (void *)&num_right_cond_busy_cpu);
+
+ ret += get_property(obj, "hotplug,num_left_cond", DATA_TYPE_INT,
+ false, (void *)&num_left_cond);
+ ret += get_property(obj, "hotplug,num_left_cond_freq", DATA_TYPE_INT,
+ false, (void *)&num_left_cond_freq);
+ ret += get_property(obj, "hotplug,num_left_cond_nr_running", DATA_TYPE_INT,
+ false, (void *)&num_left_cond_nr_running);
+ ret += get_property(obj, "hotplug,num_left_cond_busy_cpu", DATA_TYPE_INT,
+ false, (void *)&num_left_cond_busy_cpu);
+
+ ret += get_property(obj, "hotplug,governor_timeout_sec", DATA_TYPE_DOUBLE,
+ false, (void *)&governor_timeout_sec);
+
+ ret += get_property(obj, "memory,fault_around_bytes", DATA_TYPE_INT,
+ false, (void *)&fault_around_bytes);
+
+ ret += get_property(obj, "thermal,cooling_device_state", DATA_TYPE_INT,
+ false, (void *)&cooling_device_state);
+ ret += get_property(obj, "battery,charging_status", DATA_TYPE_INT,
+ false, (void *)&charging_status);
+ ret += get_property(obj, "battery,charging_current_uA", DATA_TYPE_INT,
+ false, (void *)&charging_current_uA);
+
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get the mandatory properties in level_list section\n");
return -EINVAL;
- } else if (level != level_idx) {
+ }
+
+ /* Check the validation of property value */
+ if (level != level_idx) {
_E("Invalid 'level' property value(%d) in 'level_list' section\n",
level);
return -EINVAL;
{
int pmqos_support;
json_object *pmqos_scenario_list = NULL;
- int num_scenarios = 0, ret, i;
+ int num_scenarios = 0, ret = 0, i;
/* Get property values */
- pmqos_support = get_boolean_from_object(obj, "pmqos_support");
+ ret = get_property(obj, "pmqos_support", DATA_TYPE_INT,
+ true, (void *)&pmqos_support);
if (json_object_object_get_ex(obj, "pmqos_scenario_list",
&pmqos_scenario_list))
num_scenarios = json_object_array_length(pmqos_scenario_list);
- /* Check the mandatory property values are valid or not */
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get mandatory properties in pmqos for %s\n",
+ res->config_data.res_name);
+ return -EINVAL;
+ }
+
+ /* Check the validation of property value */
if (pmqos_support <= 0)
return 0;
int thermal_support;
int thermal_timer_interval_ms;
json_object *thermal_scenario_list = NULL;
- int num_scenarios = 0, ret, i;
+ int num_scenarios = 0, ret = 0, i;
/* Get property values */
- thermal_support = get_boolean_from_object(obj, "thermal_support");
- thermal_timer_interval_ms
- = get_int_from_object(obj, "thermal_timer_interval_ms");
+ ret += get_property(obj, "thermal_support",DATA_TYPE_INT,
+ true, (void *)&thermal_support);
+ ret += get_property(obj, "thermal_timer_interval_ms", DATA_TYPE_INT,
+ false, (void *)&thermal_timer_interval_ms);
if (json_object_object_get_ex(obj, "thermal_scenario_list",
&thermal_scenario_list))
num_scenarios = json_object_array_length(thermal_scenario_list);
- /* Check the mandatory property values are valid or not */
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get mandatory properties in thermal for %s\n",
+ res->config_data.res_name);
+ return -EINVAL;
+ }
+
+ /* Check the validation of property value */
if (thermal_support <= 0)
return 0;
int cpuhp_up_threshold;
int cpuhp_down_threshold;
json_object *cpuhp_level_list = NULL;
- int cpuhp_num_levels = 0, ret, i;
+ int cpuhp_num_levels = 0, ret = 0, i;
/* Get property values */
- cpuhp_support = get_int_from_object(obj, "cpuhp_support");
- cpuhp_governor = get_int_from_object(obj, "cpuhp_governor");
- cpuhp_timer_interval_sec = get_int_from_object(obj, "cpuhp_timer_interval_sec");
- cpuhp_min_level = get_int_from_object(obj, "cpuhp_min_level");
- cpuhp_max_level = get_int_from_object(obj, "cpuhp_max_level");
- cpuhp_init_level = get_int_from_object(obj, "cpuhp_init_level");
- cpuhp_cpu_threshold = get_int_from_object(obj, "cpuhp_cpu_threshold");
- cpuhp_up_threshold = get_int_from_object(obj, "cpuhp_up_threshold");
- cpuhp_down_threshold= get_int_from_object(obj, "cpuhp_down_threshold");
+ ret += get_property(obj, "cpuhp_support", DATA_TYPE_INT,
+ true, (void *)&cpuhp_support);
+ ret += get_property(obj, "cpuhp_governor", DATA_TYPE_INT,
+ false, (void *)&cpuhp_governor);
+ ret += get_property(obj, "cpuhp_timer_interval_sec", DATA_TYPE_DOUBLE,
+ false, (void *)&cpuhp_timer_interval_sec);
+ ret += get_property(obj, "cpuhp_min_level", DATA_TYPE_INT,
+ false, (void *)&cpuhp_min_level);
+ ret += get_property(obj, "cpuhp_max_level", DATA_TYPE_INT,
+ false, (void *)&cpuhp_max_level);
+ ret += get_property(obj, "cpuhp_init_level", DATA_TYPE_INT,
+ false, (void *)&cpuhp_init_level);
+ ret += get_property(obj, "cpuhp_cpu_threshold", DATA_TYPE_INT,
+ false, (void *)&cpuhp_cpu_threshold);
+ ret += get_property(obj, "cpuhp_up_threshold", DATA_TYPE_INT,
+ false, (void *)&cpuhp_up_threshold);
+ ret += get_property(obj, "cpuhp_down_threshold", DATA_TYPE_INT,
+ false, (void *)&cpuhp_down_threshold);
if (json_object_object_get_ex(obj, "cpuhp_level_list", &cpuhp_level_list))
cpuhp_num_levels = json_object_array_length(cpuhp_level_list);
- /* Check the mandatory property values are valid or not */
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get mandatory properties in cpuhp for %s\n",
+ res->config_data.res_name);
+ return -EINVAL;
+ }
+
+ /* Check the validation of property value */
if (cpuhp_support <= 0) {
return 0;
- } else if (cpuhp_governor < 0) {
- _E("Failed to get 'cpuhp_governor' property\n");
- return -EINVAL;
} else if (!cpuhp_level_list) {
_E("Failed to get 'cpuhp_level_list' property\n");
return -EINVAL;
int support;
int init_level;
json_object *level_list = NULL;
- int num_levels = 0, ret, i;
+ int num_levels = 0, ret = 0, i;
/* Get property values */
- support = get_boolean_from_object(obj, "support");
- init_level = get_int_from_object(obj, "init_level");
+ ret += get_property(obj, "support", DATA_TYPE_BOOLEAN,
+ true, (void *)&support);
+ ret += get_property(obj, "init_level", DATA_TYPE_INT,
+ true, (void *)&init_level);
if (json_object_object_get_ex(obj, "level_list", &level_list))
num_levels = json_object_array_length(level_list);
- /* Check the mandatory property values are valid or not */
- if (support < 0) {
- _E("Failed to get 'support' property\n");
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get mandatory properties in header for %s\n",
+ res->config_data.res_name);
return -EINVAL;
- } else if (!level_list) {
+ }
+
+ /* Check the validation of property value */
+ if (!level_list) {
_E("Failed to get 'level_list' property\n");
return -EINVAL;
} else if (num_levels <= 0) {
if (init_level < 0)
init_level = 0;
-
/* Initialize config_data from property values of confiugartion file */
res->config_data.state = support;
res->config_data.num_scenario_levels = num_levels;
{
struct pass_resource_config_data *config_data
= &(pass->res[id].config_data);
- const char *device_type;
- const char *device_name;
- const char *thermal_device_name;
- const char *cooling_device_name;
- const char *device_config_path;
- const char *cpu_load_path;
+ char device_type[BUFF_MAX] = {};
+ char device_name[BUFF_MAX] = {};
+ char thermal_device_name[BUFF_MAX] = {};
+ char cooling_device_name[BUFF_MAX] = {};
+ char device_config_path[BUFF_MAX] = {};
+ char cpu_load_path[BUFF_MAX] = {};
int number_of_cpus;
int first_cpu;
int thermal_priority;
+ int ret = 0;
/* Get property values */
- /* - mandatory properties */
- device_type = get_string_from_object(obj, "device_type");
- device_name = get_string_from_object(obj, "device_name");
- device_config_path = get_string_from_object(obj, "device_config_path");
-
- /* - optional properties */
- thermal_device_name = get_string_from_object(obj, "thermal_device_name");
- cooling_device_name = get_string_from_object(obj, "cooling_device_name");
- thermal_priority = get_int_from_object(obj, "thermal_priority");
- /* if thermal_priority is not set, set default */
- if (thermal_priority < 0)
- thermal_priority = INT_MAX;
-
- /* - optional properties for only CPU */
- cpu_load_path = get_string_from_object(obj, "cpu,cpu_load_path");
- number_of_cpus = get_int_from_object(obj, "cpu,number_of_cpus");
- first_cpu = get_int_from_object(obj, "cpu,first_cpu");
-
- /* Check the mandatory property values are valid or not */
- if (!device_type) {
- _E("Failed to get 'device_type' property of resource in 'device_list' of %s\n",
- config_data->res_name);
- return -EINVAL;
- } else if (!device_name) {
- _E("Failed to get 'device_name' property of resource in 'device_list' of %s\n",
- config_data->res_name);
- return -EINVAL;
- } else if (!device_config_path) {
- _E("Failed to get 'device_config_path' property of resource in 'device_list' of %s\n",
- config_data->res_name);
+ ret += get_property(obj, "device_type", DATA_TYPE_STRING,
+ true, (void *)device_type);
+ ret += get_property(obj, "device_name", DATA_TYPE_STRING,
+ true, (void *)device_name);
+ ret += get_property(obj, "device_config_path", DATA_TYPE_STRING,
+ true, (void *)device_config_path);
+
+ ret += get_property(obj, "thermal_device_name", DATA_TYPE_STRING,
+ false, (void *)thermal_device_name);
+ ret += get_property(obj, "cooling_device_name", DATA_TYPE_STRING,
+ false, (void *)cooling_device_name);
+ ret += get_property(obj, "thermal_priority", DATA_TYPE_INT,
+ false, (void *)&thermal_priority);
+
+ ret += get_property(obj, "cpu,cpu_load_path", DATA_TYPE_STRING,
+ false, (void *)cpu_load_path);
+ ret += get_property(obj, "cpu,number_of_cpus", DATA_TYPE_INT,
+ false, (void *)&number_of_cpus);
+ ret += get_property(obj, "cpu,first_cpu", DATA_TYPE_INT,
+ false, (void *)&first_cpu);
+
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get mandatory properties in device_list\n");
return -EINVAL;
}
+ /* Check the validation of property value */
+ if (thermal_priority < 0)
+ thermal_priority = INT_MAX;
+
switch (config_data->res_type) {
case PASS_RESOURCE_CPU_ID:
if (number_of_cpus < 0 || first_cpu < 0) {
- _E("Invalid 'number_of_cpus'(%d) or 'first_cpu'(%d) property value of %s\n",
- number_of_cpus, first_cpu, config_data->res_name);
+ _E("Invalid 'number_of_cpus'(%d) or 'first_cpu'(%d) property\n",
+ number_of_cpus, first_cpu);
return -EINVAL;
}
break;
static int parse_resource(struct pass *pass, json_object *obj)
{
json_object *device_list = NULL;
- const char *board_name = NULL;
- const char *board_name_path = NULL;
- int num_resources = 0, ret, i;
+ char board_name[BUFF_MAX] = {};
+ char board_name_path[BUFF_MAX] = {};
+ int num_resources = 0, ret = 0, i;
/* Get property values */
- /* - mandatory properties */
- board_name = get_string_from_object(obj, "board_name");
- board_name_path = get_string_from_object(obj, "board_name_path");
+ ret += get_property(obj, "board_name", DATA_TYPE_STRING,
+ false, (void *)board_name);
+ ret += get_property(obj, "board_name_path", DATA_TYPE_STRING,
+ false, (void *)board_name_path);
if (json_object_object_get_ex(obj, "device_list", &device_list))
num_resources = json_object_array_length(device_list);
- /* Check the optional property values are valid or not */
- if (!board_name || !board_name_path)
- _E("Failed to get 'board_name' or 'board_name_path' property\n");
+ /* Check whether the mandatory properties are included or not */
+ if (ret < 0) {
+ _E("Failed to get the mandatory properties in header\n");
+ return -EINVAL;
+ }
+
+ /* Check the validation of property value */
+ if (!strlen(board_name) || !strlen(board_name_path))
+ _W("There are no 'board_name' or 'board_name_path' property\n");
+ else {
+ ret = compare_compatible_name(board_name, board_name_path);
+ if (ret < 0) {
+ _E("Cannot match 'board_name' from 'board_name_path'\n");
+ return -EINVAL;
+ }
+ }
- /* Check the mandatory property values are valid or not */
if (!device_list) {
_E("Failed to get 'device_list' property\n");
return -EINVAL;
return -EINVAL;
}
- ret = compare_compatible_name(board_name, board_name_path);
- if (ret < 0) {
- _E("Cannot match 'board_name' from 'board_name_path'\n");
- return -EINVAL;
- }
-
/* Initialize config_data from property values of confiugartion file */
pass->res = calloc(num_resources, sizeof(struct pass_resource));
if (!pass->res) {