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 {
int num_ctrls;
const struct resource_control *ctrls;
u_int64_t attr_interest;
+ u_int64_t attr_supported;
};
#define RESOURCE_DRIVER_REGISTER(resource_driver) \
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);
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);
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",