From: Chanwoo Choi Date: Thu, 10 Mar 2022 07:11:29 +0000 (+0900) Subject: util: resource: Add is_resource_attr_supported function X-Git-Tag: submit/tizen/20220311.083421~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59d457200fd604d60f5cac3cf26e04af78a3ec7c;p=platform%2Fcore%2Fsystem%2Fpass.git util: resource: Add is_resource_attr_supported function is_resource_attr_supported(struct resource *resource, u_int64_t attr_id) checks whether resource attribute of attr_id is supported or not on board. In order to check the support of resource attribute, add .is_supported ops to struct resource_attribute_ops. But if .is_supported ops is not implemented, use .get ops in order to check whether the resource attribute is supported or not. Change-Id: I0b4ed0579c6602e43ff6b3544b4d136707440124 Signed-off-by: Chanwoo Choi --- diff --git a/include/util/resource.h b/include/util/resource.h index ec3d821..ec1f496 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -59,6 +59,12 @@ struct resource_attribute_ops { int (*get)(const struct resource *res, const struct resource_attribute *attr, void *data); + /* + * If .is_supported ops is not implemented, use .get ops in order to + * check whether the resource attribute is supported or not. + */ + bool (*is_supported)(const struct resource *res, + const struct resource_attribute *attr); }; struct resource_attribute { @@ -129,6 +135,7 @@ struct resource { int num_ctrls; const struct resource_control *ctrls; u_int64_t attr_interest; + u_int64_t attr_supported; }; #define RESOURCE_DRIVER_REGISTER(resource_driver) \ @@ -163,6 +170,7 @@ int update_resource_attrs(struct resource *resource); const struct resource_attribute *get_resource_attr(struct resource *resource, u_int64_t attr_id); struct resource_attribute_value * get_resource_attr_value(struct resource *resource, u_int64_t attr_id); +bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id); int get_resource_attr_int(struct resource *resource, u_int64_t attr_id, int32_t *data); int get_resource_attr_int64(struct resource *resource, u_int64_t attr_id, int64_t *data); diff --git a/src/util/resource.c b/src/util/resource.c index a03631d..6605154 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -292,6 +292,40 @@ get_resource_attr_value(struct resource *resource, u_int64_t attr_id) return &resource->attrs_value[attr_index]; } +bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id) +{ + const struct resource_attribute *attr = NULL; + int attr_index = RESOURCE_ATTR_INDEX(attr_id); + int ret; + bool is_supported = false; + + if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) + return false; + + attr = &resource->attrs[attr_index]; + + if (attr->id & resource->attr_supported) { + return true; + } else if (attr->ops.is_supported) { + is_supported = attr->ops.is_supported(resource, attr); + } else if (attr->ops.get) { + /* + * Optionally, if .is_supported ops is not implemented, + * use .get ops in order to check whether the resource attribute + * is supported or not. + */ + char data[BUFF_MAX] = {0, }; + + ret = attr->ops.get(resource, attr, (void *)data); + is_supported = (ret < 0) ? false : true; + } + + if (is_supported) + resource->attr_supported |= attr->id; + + return is_supported; +} + static bool check_attr_validate(struct resource *resource, u_int64_t attr_id, int type) { const struct resource_attribute *attr = get_resource_attr(resource, attr_id); @@ -445,6 +479,11 @@ int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mas if (!(resource->attrs[i].id & interest_mask)) continue; + if (!is_resource_attr_supported(resource, resource->attrs[i].id)) { + ret = -EINVAL; + goto err; + } + attr_value = get_resource_attr_value(resource, resource->attrs[i].id); if (!attr_value) { _E("failed to get attribute value: resource: %s, attribute: %s",