/** * DOC: overview * * The component helper allows drivers to collect a pile of sub-devices, * including their bound drivers, into an aggregate driver. Various subsystems * already provide functions to get hold of such components, e.g. * of_clk_get_by_name(). The component helper can be used when such a * subsystem-specific way to find a device is not available: The component * helper fills the niche of aggregate drivers for specific hardware, where * further standardization into a subsystem would not be practical. The common * example is when a logical device (e.g. a DRM display driver) is spread around * the SoC on various components (scanout engines, blending blocks, transcoders * for various outputs and so on). * * The component helper also doesn't solve runtime dependencies, e.g. for system * suspend and resume operations. See also :ref:`device links<device_link>`. * * Components are registered using component_add() and unregistered with * component_del(), usually from the driver's probe and disconnect functions. * * Aggregate drivers first assemble a component match list of what they need * using component_match_add(). This is then registered as an aggregate driver * using component_master_add_with_match(), and unregistered using * component_master_del().
*/
if (mc->compare && mc->compare(c->dev, mc->data)) return c;
if (mc->compare_typed &&
mc->compare_typed(c->dev, c->subcomponent, mc->data)) return c;
}
return NULL;
}
staticint find_components(struct aggregate_device *adev)
{ struct component_match *match = adev->match;
size_t i; int ret = 0;
/* * Scan the array of match functions and attach * any components which are found to this adev.
*/ for (i = 0; i < match->num; i++) { struct component_match_array *mc = &match->compare[i]; struct component *c;
dev_dbg(adev->parent, "Looking for component %zu\n", i);
if (match->compare[i].component) continue;
c = find_component(adev, mc); if (!c) {
ret = -ENXIO; break;
}
/* Detach the component from this adev. */ for (i = 0; i < adev->match->num; i++) if (adev->match->compare[i].component == c)
adev->match->compare[i].component = NULL;
}
/* * Try to bring up an aggregate device. If component is NULL, we're interested * in this aggregate device, otherwise it's a component which must be present * to try and bring up the aggregate device. * * Returns 1 for successful bringup, 0 if not ready, or -ve errno.
*/ staticint try_to_bring_up_aggregate_device(struct aggregate_device *adev, struct component *component)
{ int ret;
dev_dbg(adev->parent, "trying to bring up adev\n");
if (find_components(adev)) {
dev_dbg(adev->parent, "master has incomplete components\n"); return 0;
}
if (component && component->adev != adev) {
dev_dbg(adev->parent, "master is not for this component (%s)\n",
dev_name(component->dev)); return 0;
}
if (!devres_open_group(adev->parent, adev, GFP_KERNEL)) return -ENOMEM;
/* Found all components */
ret = adev->ops->bind(adev->parent); if (ret < 0) {
devres_release_group(adev->parent, NULL); if (ret != -EPROBE_DEFER)
dev_info(adev->parent, "adev bind failed: %d\n", ret); return ret;
}
/** * component_compare_of - A common component compare function for of_node * @dev: component device * @data: @compare_data from component_match_add_release() * * A common compare function when compare_data is device of_node. e.g. * component_match_add_release(masterdev, &match, component_release_of, * component_compare_of, component_dev_of_node)
*/ int component_compare_of(struct device *dev, void *data)
{ return device_match_of_node(dev, data);
}
EXPORT_SYMBOL_GPL(component_compare_of);
/** * component_release_of - A common component release function for of_node * @dev: component device * @data: @compare_data from component_match_add_release() * * About the example, Please see component_compare_of().
*/ void component_release_of(struct device *dev, void *data)
{
of_node_put(data);
}
EXPORT_SYMBOL_GPL(component_release_of);
/** * component_compare_dev - A common component compare function for dev * @dev: component device * @data: @compare_data from component_match_add_release() * * A common compare function when compare_data is struce device. e.g. * component_match_add(masterdev, &match, component_compare_dev, component_dev)
*/ int component_compare_dev(struct device *dev, void *data)
{ return dev == data;
}
EXPORT_SYMBOL_GPL(component_compare_dev);
/** * component_compare_dev_name - A common component compare function for device name * @dev: component device * @data: @compare_data from component_match_add_release() * * A common compare function when compare_data is device name string. e.g. * component_match_add(masterdev, &match, component_compare_dev_name, * "component_dev_name")
*/ int component_compare_dev_name(struct device *dev, void *data)
{ return device_match_name(dev, data);
}
EXPORT_SYMBOL_GPL(component_compare_dev_name);
/** * component_match_add_release - add a component match entry with release callback * @parent: parent device of the aggregate driver * @matchptr: pointer to the list of component matches * @release: release function for @compare_data * @compare: compare function to match against all components * @compare_data: opaque pointer passed to the @compare function * * Adds a new component match to the list stored in @matchptr, which the * aggregate driver needs to function. The list of component matches pointed to * by @matchptr must be initialized to NULL before adding the first match. This * only matches against components added with component_add(). * * The allocated match list in @matchptr is automatically released using devm * actions, where upon @release will be called to free any references held by * @compare_data, e.g. when @compare_data is a &device_node that must be * released with of_node_put(). * * See also component_match_add() and component_match_add_typed().
*/ void component_match_add_release(struct device *parent, struct component_match **matchptr, void (*release)(struct device *, void *), int (*compare)(struct device *, void *), void *compare_data)
{
__component_match_add(parent, matchptr, release, compare, NULL,
compare_data);
}
EXPORT_SYMBOL(component_match_add_release);
/** * component_match_add_typed - add a component match entry for a typed component * @parent: parent device of the aggregate driver * @matchptr: pointer to the list of component matches * @compare_typed: compare function to match against all typed components * @compare_data: opaque pointer passed to the @compare function * * Adds a new component match to the list stored in @matchptr, which the * aggregate driver needs to function. The list of component matches pointed to * by @matchptr must be initialized to NULL before adding the first match. This * only matches against components added with component_add_typed(). * * The allocated match list in @matchptr is automatically released using devm * actions. * * See also component_match_add_release() and component_match_add_typed().
*/ void component_match_add_typed(struct device *parent, struct component_match **matchptr, int (*compare_typed)(struct device *, int, void *), void *compare_data)
{
__component_match_add(parent, matchptr, NULL, NULL, compare_typed,
compare_data);
}
EXPORT_SYMBOL(component_match_add_typed);
if (match) { for (i = 0; i < match->num; i++) { struct component *c = match->compare[i].component; if (c)
c->adev = NULL;
}
}
kfree(adev);
}
/** * component_master_add_with_match - register an aggregate driver * @parent: parent device of the aggregate driver * @ops: callbacks for the aggregate driver * @match: component match list for the aggregate driver * * Registers a new aggregate driver consisting of the components added to @match * by calling one of the component_match_add() functions. Once all components in * @match are available, it will be assembled by calling * &component_master_ops.bind from @ops. Must be unregistered by calling * component_master_del().
*/ int component_master_add_with_match(struct device *parent, conststruct component_master_ops *ops, struct component_match *match)
{ struct aggregate_device *adev; int ret;
/* Reallocate the match array for its true size */
ret = component_match_realloc(match, match->num); if (ret) return ret;
adev = kzalloc(sizeof(*adev), GFP_KERNEL); if (!adev) return -ENOMEM;
component_debugfs_add(adev); /* Add to the list of available aggregate devices. */
mutex_lock(&component_mutex);
list_add(&adev->node, &aggregate_devices);
ret = try_to_bring_up_aggregate_device(adev, NULL);
if (ret < 0)
free_aggregate_device(adev);
mutex_unlock(&component_mutex);
return ret < 0 ? ret : 0;
}
EXPORT_SYMBOL_GPL(component_master_add_with_match);
/** * component_master_del - unregister an aggregate driver * @parent: parent device of the aggregate driver * @ops: callbacks for the aggregate driver * * Unregisters an aggregate driver registered with * component_master_add_with_match(). If necessary the aggregate driver is first * disassembled by calling &component_master_ops.unbind from @ops.
*/ void component_master_del(struct device *parent, conststruct component_master_ops *ops)
{ struct aggregate_device *adev;
if (component->ops && component->ops->unbind)
component->ops->unbind(component->dev, adev->parent, data);
component->bound = false;
/* Release all resources claimed in the binding of this component */
devres_release_group(component->dev, component);
}
/** * component_unbind_all - unbind all components of an aggregate driver * @parent: parent device of the aggregate driver * @data: opaque pointer, passed to all components * * Unbinds all components of the aggregate device by passing @data to their * &component_ops.unbind functions. Should be called from * &component_master_ops.unbind.
*/ void component_unbind_all(struct device *parent, void *data)
{ struct aggregate_device *adev; struct component *c;
size_t i;
WARN_ON(!mutex_is_locked(&component_mutex));
adev = __aggregate_find(parent, NULL); if (!adev) return;
/* Unbind components in reverse order */ for (i = adev->match->num; i--; ) if (!adev->match->compare[i].duplicate) {
c = adev->match->compare[i].component;
component_unbind(c, adev, data);
}
}
EXPORT_SYMBOL_GPL(component_unbind_all);
/* * Each component initialises inside its own devres group. * This allows us to roll-back a failed component without * affecting anything else.
*/ if (!devres_open_group(adev->parent, NULL, GFP_KERNEL)) return -ENOMEM;
/* * Also open a group for the device itself: this allows us * to release the resources claimed against the sub-device * at the appropriate moment.
*/ if (!devres_open_group(component->dev, component, GFP_KERNEL)) {
devres_release_group(adev->parent, NULL); return -ENOMEM;
}
ret = component->ops->bind(component->dev, adev->parent, data); if (!ret) {
component->bound = true;
/* * Close the component device's group so that resources * allocated in the binding are encapsulated for removal * at unbind. Remove the group on the DRM device as we * can clean those resources up independently.
*/
devres_close_group(component->dev, NULL);
devres_remove_group(adev->parent, NULL);
if (ret != -EPROBE_DEFER)
dev_err(adev->parent, "failed to bind %s (ops %ps): %d\n",
dev_name(component->dev), component->ops, ret);
}
return ret;
}
/** * component_bind_all - bind all components of an aggregate driver * @parent: parent device of the aggregate driver * @data: opaque pointer, passed to all components * * Binds all components of the aggregate @dev by passing @data to their * &component_ops.bind functions. Should be called from * &component_master_ops.bind.
*/ int component_bind_all(struct device *parent, void *data)
{ struct aggregate_device *adev; struct component *c;
size_t i; int ret = 0;
WARN_ON(!mutex_is_locked(&component_mutex));
adev = __aggregate_find(parent, NULL); if (!adev) return -EINVAL;
/* Bind components in match order */ for (i = 0; i < adev->match->num; i++) if (!adev->match->compare[i].duplicate) {
c = adev->match->compare[i].component;
ret = component_bind(c, adev, data); if (ret) break;
}
if (ret != 0) { for (; i > 0; i--) if (!adev->match->compare[i - 1].duplicate) {
c = adev->match->compare[i - 1].component;
component_unbind(c, adev, data);
}
}
ret = try_to_bring_up_masters(component); if (ret < 0) { if (component->adev)
remove_component(component->adev, component);
list_del(&component->node);
/** * component_add_typed - register a component * @dev: component device * @ops: component callbacks * @subcomponent: nonzero identifier for subcomponents * * Register a new component for @dev. Functions in @ops will be call when the * aggregate driver is ready to bind the overall driver by calling * component_bind_all(). See also &struct component_ops. * * @subcomponent must be nonzero and is used to differentiate between multiple * components registered on the same device @dev. These components are match * using component_match_add_typed(). * * The component needs to be unregistered at driver unload/disconnect by * calling component_del(). * * See also component_add().
*/ int component_add_typed(struct device *dev, conststruct component_ops *ops, int subcomponent)
{ if (WARN_ON(subcomponent == 0)) return -EINVAL;
/** * component_add - register a component * @dev: component device * @ops: component callbacks * * Register a new component for @dev. Functions in @ops will be called when the * aggregate driver is ready to bind the overall driver by calling * component_bind_all(). See also &struct component_ops. * * The component needs to be unregistered at driver unload/disconnect by * calling component_del(). * * See also component_add_typed() for a variant that allows multiple different * components on the same device.
*/ int component_add(struct device *dev, conststruct component_ops *ops)
{ return __component_add(dev, ops, 0);
}
EXPORT_SYMBOL_GPL(component_add);
/** * component_del - unregister a component * @dev: component device * @ops: component callbacks * * Unregister a component added with component_add(). If the component is bound * into an aggregate driver, this will force the entire aggregate driver, including * all its components, to be unbound.
*/ void component_del(struct device *dev, conststruct component_ops *ops)
{ struct component *c, *component = NULL;
mutex_lock(&component_mutex);
list_for_each_entry(c, &component_list, node) if (c->dev == dev && c->ops == ops) {
list_del(&c->node);
component = c; break;
}
if (component && component->adev) {
take_down_aggregate_device(component->adev);
remove_component(component->adev, component);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.