2017-11-07 19:30:07 +03:00
// SPDX-License-Identifier: GPL-2.0
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
/*
* Componentized device handling .
*
* This is work in progress . We gather up the component devices into a list ,
* and bind them when instructed . At the moment , we ' re specific to the DRM
* subsystem , and only handles one master device , but this doesn ' t have to be
* the case .
*/
# include <linux/component.h>
# include <linux/device.h>
# include <linux/kref.h>
# include <linux/list.h>
# include <linux/module.h>
# include <linux/mutex.h>
# include <linux/slab.h>
2017-12-01 16:23:16 +03:00
# include <linux/debugfs.h>
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
2014-04-19 02:05:53 +04:00
struct component ;
2015-11-17 15:08:01 +03:00
struct component_match_array {
void * data ;
int ( * compare ) ( struct device * , void * ) ;
void ( * release ) ( struct device * , void * ) ;
struct component * component ;
bool duplicate ;
} ;
2014-04-19 14:18:01 +04:00
struct component_match {
size_t alloc ;
size_t num ;
2015-11-17 15:08:01 +03:00
struct component_match_array * compare ;
2014-04-19 14:18:01 +04:00
} ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
struct master {
struct list_head node ;
bool bound ;
const struct component_master_ops * ops ;
struct device * dev ;
2014-04-19 14:18:01 +04:00
struct component_match * match ;
2017-12-01 16:23:16 +03:00
struct dentry * dentry ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
} ;
struct component {
struct list_head node ;
struct master * master ;
bool bound ;
const struct component_ops * ops ;
struct device * dev ;
} ;
static DEFINE_MUTEX ( component_mutex ) ;
static LIST_HEAD ( component_list ) ;
static LIST_HEAD ( masters ) ;
2017-12-01 16:23:16 +03:00
# ifdef CONFIG_DEBUG_FS
static struct dentry * component_debugfs_dir ;
static int component_devices_show ( struct seq_file * s , void * data )
{
struct master * m = s - > private ;
struct component_match * match = m - > match ;
size_t i ;
mutex_lock ( & component_mutex ) ;
seq_printf ( s , " %-40s %20s \n " , " master name " , " status " ) ;
seq_puts ( s , " ------------------------------------------------------------- \n " ) ;
seq_printf ( s , " %-40s %20s \n \n " ,
dev_name ( m - > dev ) , m - > bound ? " bound " : " not bound " ) ;
seq_printf ( s , " %-40s %20s \n " , " device name " , " status " ) ;
seq_puts ( s , " ------------------------------------------------------------- \n " ) ;
for ( i = 0 ; i < match - > num ; i + + ) {
struct device * d = ( struct device * ) match - > compare [ i ] . data ;
seq_printf ( s , " %-40s %20s \n " , dev_name ( d ) ,
match - > compare [ i ] . component ?
" registered " : " not registered " ) ;
}
mutex_unlock ( & component_mutex ) ;
return 0 ;
}
static int component_devices_open ( struct inode * inode , struct file * file )
{
return single_open ( file , component_devices_show , inode - > i_private ) ;
}
static const struct file_operations component_devices_fops = {
. open = component_devices_open ,
. read = seq_read ,
. llseek = seq_lseek ,
. release = single_release ,
} ;
static int __init component_debug_init ( void )
{
component_debugfs_dir = debugfs_create_dir ( " device_component " , NULL ) ;
return 0 ;
}
core_initcall ( component_debug_init ) ;
static void component_master_debugfs_add ( struct master * m )
{
m - > dentry = debugfs_create_file ( dev_name ( m - > dev ) , 0444 ,
component_debugfs_dir ,
m , & component_devices_fops ) ;
}
static void component_master_debugfs_del ( struct master * m )
{
debugfs_remove ( m - > dentry ) ;
m - > dentry = NULL ;
}
# else
static void component_master_debugfs_add ( struct master * m )
{ }
static void component_master_debugfs_del ( struct master * m )
{ }
# endif
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
static struct master * __master_find ( struct device * dev ,
const struct component_master_ops * ops )
{
struct master * m ;
list_for_each_entry ( m , & masters , node )
if ( m - > dev = = dev & & ( ! ops | | m - > ops = = ops ) )
return m ;
return NULL ;
}
2014-04-19 02:05:53 +04:00
static struct component * find_component ( struct master * master ,
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
int ( * compare ) ( struct device * , void * ) , void * compare_data )
{
struct component * c ;
list_for_each_entry ( c , & component_list , node ) {
2014-04-18 23:16:22 +04:00
if ( c - > master & & c - > master ! = master )
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
continue ;
2014-04-19 02:05:53 +04:00
if ( compare ( c - > dev , compare_data ) )
return c ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
2014-04-19 02:05:53 +04:00
return NULL ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
2014-04-19 14:18:01 +04:00
static int find_components ( struct master * master )
{
struct component_match * match = master - > match ;
size_t i ;
int ret = 0 ;
/*
* Scan the array of match functions and attach
* any components which are found to this master .
*/
for ( i = 0 ; i < match - > num ; i + + ) {
2015-11-17 15:08:01 +03:00
struct component_match_array * mc = & match - > compare [ i ] ;
2014-04-19 02:05:53 +04:00
struct component * c ;
dev_dbg ( master - > dev , " Looking for component %zu \n " , i ) ;
if ( match - > compare [ i ] . component )
continue ;
2015-11-17 15:08:01 +03:00
c = find_component ( master , mc - > compare , mc - > data ) ;
2014-04-19 02:05:53 +04:00
if ( ! c ) {
ret = - ENXIO ;
2014-04-19 14:18:01 +04:00
break ;
2014-04-19 02:05:53 +04:00
}
dev_dbg ( master - > dev , " found component %s, duplicate %u \n " , dev_name ( c - > dev ) , ! ! c - > master ) ;
/* Attach this component to the master */
match - > compare [ i ] . duplicate = ! ! c - > master ;
match - > compare [ i ] . component = c ;
c - > master = master ;
2014-04-19 14:18:01 +04:00
}
return ret ;
}
2014-04-19 02:05:53 +04:00
/* Detach component from associated master */
static void remove_component ( struct master * master , struct component * c )
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
{
2014-04-19 02:05:53 +04:00
size_t i ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
2014-04-19 02:05:53 +04:00
/* Detach the component from this master. */
for ( i = 0 ; i < master - > match - > num ; i + + )
if ( master - > match - > compare [ i ] . component = = c )
master - > match - > compare [ i ] . component = NULL ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
/*
* Try to bring up a master . If component is NULL , we ' re interested in
* this master , otherwise it ' s a component which must be present to try
* and bring up the master .
*
* Returns 1 for successful bringup , 0 if not ready , or - ve errno .
*/
static int try_to_bring_up_master ( struct master * master ,
struct component * component )
{
2014-04-23 13:52:17 +04:00
int ret ;
2014-04-19 02:05:53 +04:00
dev_dbg ( master - > dev , " trying to bring up master \n " ) ;
2014-04-19 14:18:01 +04:00
if ( find_components ( master ) ) {
2014-04-19 02:05:53 +04:00
dev_dbg ( master - > dev , " master has incomplete components \n " ) ;
return 0 ;
2014-04-23 13:52:17 +04:00
}
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
2014-04-23 13:52:17 +04:00
if ( component & & component - > master ! = master ) {
2014-04-19 02:05:53 +04:00
dev_dbg ( master - > dev , " master is not for this component (%s) \n " ,
dev_name ( component - > dev ) ) ;
return 0 ;
2014-04-23 13:52:17 +04:00
}
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
2014-04-19 02:05:53 +04:00
if ( ! devres_open_group ( master - > dev , NULL , GFP_KERNEL ) )
return - ENOMEM ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
2014-04-23 13:52:17 +04:00
/* Found all components */
ret = master - > ops - > bind ( master - > dev ) ;
if ( ret < 0 ) {
devres_release_group ( master - > dev , NULL ) ;
dev_info ( master - > dev , " master bind failed: %d \n " , ret ) ;
2014-04-19 02:05:53 +04:00
return ret ;
2014-04-23 13:52:17 +04:00
}
2014-02-08 00:09:27 +04:00
2014-04-23 13:52:17 +04:00
master - > bound = true ;
return 1 ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
static int try_to_bring_up_masters ( struct component * component )
{
struct master * m ;
int ret = 0 ;
list_for_each_entry ( m , & masters , node ) {
2014-04-23 13:46:11 +04:00
if ( ! m - > bound ) {
ret = try_to_bring_up_master ( m , component ) ;
if ( ret ! = 0 )
break ;
}
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
return ret ;
}
static void take_down_master ( struct master * master )
{
if ( master - > bound ) {
master - > ops - > unbind ( master - > dev ) ;
2014-02-08 00:09:27 +04:00
devres_release_group ( master - > dev , NULL ) ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
master - > bound = false ;
}
}
2015-11-17 15:08:01 +03:00
static void component_match_release ( struct device * master ,
struct component_match * match )
2014-04-19 14:18:01 +04:00
{
2015-11-17 15:08:01 +03:00
unsigned int i ;
for ( i = 0 ; i < match - > num ; i + + ) {
struct component_match_array * mc = & match - > compare [ i ] ;
if ( mc - > release )
mc - > release ( master , mc - > data ) ;
}
2016-01-26 17:49:22 +03:00
kfree ( match - > compare ) ;
2014-04-19 14:18:01 +04:00
}
2015-11-17 15:08:01 +03:00
static void devm_component_match_release ( struct device * dev , void * res )
{
component_match_release ( dev , res ) ;
}
static int component_match_realloc ( struct device * dev ,
2014-04-19 14:18:01 +04:00
struct component_match * match , size_t num )
{
2015-11-17 15:08:01 +03:00
struct component_match_array * new ;
2014-04-19 14:18:01 +04:00
2015-11-17 15:08:01 +03:00
if ( match - > alloc = = num )
return 0 ;
2014-04-19 14:18:01 +04:00
2016-01-26 17:49:22 +03:00
new = kmalloc_array ( num , sizeof ( * new ) , GFP_KERNEL ) ;
2014-04-19 14:18:01 +04:00
if ( ! new )
2015-11-17 15:08:01 +03:00
return - ENOMEM ;
2014-04-19 14:18:01 +04:00
2015-11-17 15:08:01 +03:00
if ( match - > compare ) {
memcpy ( new , match - > compare , sizeof ( * new ) *
min ( match - > num , num ) ) ;
2016-01-26 17:49:22 +03:00
kfree ( match - > compare ) ;
2014-04-19 14:18:01 +04:00
}
2015-11-17 15:08:01 +03:00
match - > compare = new ;
match - > alloc = num ;
2014-04-19 14:18:01 +04:00
2015-11-17 15:08:01 +03:00
return 0 ;
2014-04-19 14:18:01 +04:00
}
/*
2015-11-17 15:08:01 +03:00
* Add a component to be matched , with a release function .
2014-04-19 14:18:01 +04:00
*
* The match array is first created or extended if necessary .
*/
2015-11-17 15:08:01 +03:00
void component_match_add_release ( struct device * master ,
struct component_match * * matchptr ,
void ( * release ) ( struct device * , void * ) ,
2014-04-19 14:18:01 +04:00
int ( * compare ) ( struct device * , void * ) , void * compare_data )
{
struct component_match * match = * matchptr ;
if ( IS_ERR ( match ) )
return ;
2015-11-17 15:08:01 +03:00
if ( ! match ) {
match = devres_alloc ( devm_component_match_release ,
sizeof ( * match ) , GFP_KERNEL ) ;
if ( ! match ) {
* matchptr = ERR_PTR ( - ENOMEM ) ;
return ;
}
2014-04-19 14:18:01 +04:00
2015-11-17 15:08:01 +03:00
devres_add ( master , match ) ;
2014-04-19 14:18:01 +04:00
* matchptr = match ;
2015-11-17 15:08:01 +03:00
}
2014-04-19 14:18:01 +04:00
2015-11-17 15:08:01 +03:00
if ( match - > num = = match - > alloc ) {
2016-02-02 10:27:53 +03:00
size_t new_size = match - > alloc + 16 ;
2015-11-17 15:08:01 +03:00
int ret ;
ret = component_match_realloc ( master , match , new_size ) ;
if ( ret ) {
* matchptr = ERR_PTR ( ret ) ;
2014-04-19 14:18:01 +04:00
return ;
2015-11-17 15:08:01 +03:00
}
2014-04-19 14:18:01 +04:00
}
2015-11-17 15:08:01 +03:00
match - > compare [ match - > num ] . compare = compare ;
match - > compare [ match - > num ] . release = release ;
2014-04-19 14:18:01 +04:00
match - > compare [ match - > num ] . data = compare_data ;
2014-04-19 02:05:53 +04:00
match - > compare [ match - > num ] . component = NULL ;
2014-04-19 14:18:01 +04:00
match - > num + + ;
}
2015-11-17 15:08:01 +03:00
EXPORT_SYMBOL ( component_match_add_release ) ;
2014-04-19 14:18:01 +04:00
2016-01-26 20:59:13 +03:00
static void free_master ( struct master * master )
{
struct component_match * match = master - > match ;
int i ;
2017-12-01 16:23:16 +03:00
component_master_debugfs_del ( master ) ;
2016-01-26 20:59:13 +03:00
list_del ( & master - > node ) ;
if ( match ) {
for ( i = 0 ; i < match - > num ; i + + ) {
struct component * c = match - > compare [ i ] . component ;
if ( c )
c - > master = NULL ;
}
}
kfree ( master ) ;
}
2014-04-19 14:18:01 +04:00
int component_master_add_with_match ( struct device * dev ,
const struct component_master_ops * ops ,
struct component_match * match )
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
{
struct master * master ;
int ret ;
2014-04-19 01:10:32 +04:00
/* Reallocate the match array for its true size */
2015-11-17 15:08:01 +03:00
ret = component_match_realloc ( dev , match , match - > num ) ;
if ( ret )
return ret ;
2014-04-19 14:18:01 +04:00
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
master = kzalloc ( sizeof ( * master ) , GFP_KERNEL ) ;
if ( ! master )
return - ENOMEM ;
master - > dev = dev ;
master - > ops = ops ;
2014-04-19 14:18:01 +04:00
master - > match = match ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
2017-12-01 16:23:16 +03:00
component_master_debugfs_add ( master ) ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
/* Add to the list of available masters. */
mutex_lock ( & component_mutex ) ;
list_add ( & master - > node , & masters ) ;
ret = try_to_bring_up_master ( master , NULL ) ;
2016-01-26 20:59:13 +03:00
if ( ret < 0 )
free_master ( master ) ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
mutex_unlock ( & component_mutex ) ;
return ret < 0 ? ret : 0 ;
}
2014-04-19 14:18:01 +04:00
EXPORT_SYMBOL_GPL ( component_master_add_with_match ) ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
void component_master_del ( struct device * dev ,
const struct component_master_ops * ops )
{
struct master * master ;
mutex_lock ( & component_mutex ) ;
master = __master_find ( dev , ops ) ;
if ( master ) {
take_down_master ( master ) ;
2016-01-26 20:59:13 +03:00
free_master ( master ) ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
mutex_unlock ( & component_mutex ) ;
}
EXPORT_SYMBOL_GPL ( component_master_del ) ;
static void component_unbind ( struct component * component ,
struct master * master , void * data )
{
WARN_ON ( ! component - > bound ) ;
component - > ops - > unbind ( component - > dev , master - > dev , data ) ;
component - > bound = false ;
/* Release all resources claimed in the binding of this component */
devres_release_group ( component - > dev , component ) ;
}
void component_unbind_all ( struct device * master_dev , void * data )
{
struct master * master ;
struct component * c ;
2014-04-19 02:05:53 +04:00
size_t i ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
WARN_ON ( ! mutex_is_locked ( & component_mutex ) ) ;
master = __master_find ( master_dev , NULL ) ;
if ( ! master )
return ;
2014-04-19 02:05:53 +04:00
/* Unbind components in reverse order */
for ( i = master - > match - > num ; i - - ; )
if ( ! master - > match - > compare [ i ] . duplicate ) {
c = master - > match - > compare [ i ] . component ;
component_unbind ( c , master , data ) ;
}
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
EXPORT_SYMBOL_GPL ( component_unbind_all ) ;
static int component_bind ( struct component * component , struct master * master ,
void * data )
{
int ret ;
/*
* 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 ( master - > dev , 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 ( master - > dev , NULL ) ;
return - ENOMEM ;
}
dev_dbg ( master - > dev , " binding %s (ops %ps) \n " ,
dev_name ( component - > dev ) , component - > ops ) ;
ret = component - > ops - > bind ( component - > dev , master - > dev , 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 ( master - > dev , NULL ) ;
dev_info ( master - > dev , " bound %s (ops %ps) \n " ,
dev_name ( component - > dev ) , component - > ops ) ;
} else {
devres_release_group ( component - > dev , NULL ) ;
devres_release_group ( master - > dev , NULL ) ;
dev_err ( master - > dev , " failed to bind %s (ops %ps): %d \n " ,
dev_name ( component - > dev ) , component - > ops , ret ) ;
}
return ret ;
}
int component_bind_all ( struct device * master_dev , void * data )
{
struct master * master ;
struct component * c ;
2014-04-19 02:05:53 +04:00
size_t i ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
int ret = 0 ;
WARN_ON ( ! mutex_is_locked ( & component_mutex ) ) ;
master = __master_find ( master_dev , NULL ) ;
if ( ! master )
return - EINVAL ;
2014-04-19 02:05:53 +04:00
/* Bind components in match order */
for ( i = 0 ; i < master - > match - > num ; i + + )
if ( ! master - > match - > compare [ i ] . duplicate ) {
c = master - > match - > compare [ i ] . component ;
ret = component_bind ( c , master , data ) ;
if ( ret )
break ;
}
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
if ( ret ! = 0 ) {
2014-04-19 02:05:53 +04:00
for ( ; i - - ; )
if ( ! master - > match - > compare [ i ] . duplicate ) {
c = master - > match - > compare [ i ] . component ;
component_unbind ( c , master , data ) ;
}
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
}
return ret ;
}
EXPORT_SYMBOL_GPL ( component_bind_all ) ;
int component_add ( struct device * dev , const struct component_ops * ops )
{
struct component * component ;
int ret ;
component = kzalloc ( sizeof ( * component ) , GFP_KERNEL ) ;
if ( ! component )
return - ENOMEM ;
component - > ops = ops ;
component - > dev = dev ;
dev_dbg ( dev , " adding component (ops %ps) \n " , ops ) ;
mutex_lock ( & component_mutex ) ;
list_add_tail ( & component - > node , & component_list ) ;
ret = try_to_bring_up_masters ( component ) ;
if ( ret < 0 ) {
component: remove device from master match list on failed add
Calling component_add() may result in the completion of a set of
devices, which will try to bring up a master. In bringing the master
up, we populate its match array with the current set of children.
If binding any of the devices fails, component_add() itself will fail,
free the struct component entry, and return to the caller. The
now-freed entry is never removed from the master's match array, and
will later be used in a futile attempt to bind to freed memory.
Bring component_add's behaviour on failure to bring up a master into
line with component_del by removing the (to-be-freed) component from
the master's match array.
The specific case which broke was:
- rockchip_drm_drv adds a component master
- dwhdmi_rockchip adds a child component in probe (master incomplete)
- rockchip_drm_vop adds two children in probe, which completes the
set
- inside component_add, we try to bring up the master, having
populated the master's match array, and fail with EPROBE_DEFER from
dwhdmi_rockchip; we delete the putative component
- rockchip_drm_vop's probe fails and returns EPROBE_DEFER
- we later re-probe rockchip_drm_vop and add the component; the
master is complete, so we attempt to bring it up again
- walking the match array, we find the previous child, whose master
pointer doesn't match (as it has been freed in the meantime)
- rockchip_drm_vop probe fails, and will never be attempted again
Fixes: ffc30b74fd6d01588bd3fdebc3b1acc0857e6fc8
Signed-off-by: Daniel Stone <daniels@collabora.com>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2016-02-09 00:12:58 +03:00
if ( component - > master )
remove_component ( component - > master , component ) ;
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
list_del ( & component - > node ) ;
kfree ( component ) ;
}
mutex_unlock ( & component_mutex ) ;
return ret < 0 ? ret : 0 ;
}
EXPORT_SYMBOL_GPL ( component_add ) ;
void component_del ( struct device * dev , const struct 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 ;
}
2014-04-19 02:05:53 +04:00
if ( component & & component - > master ) {
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
take_down_master ( component - > master ) ;
2014-04-19 02:05:53 +04:00
remove_component ( component - > master , component ) ;
}
drivers/base: provide an infrastructure for componentised subsystems
Subsystems such as ALSA, DRM and others require a single card-level
device structure to represent a subsystem. However, firmware tends to
describe the individual devices and the connections between them.
Therefore, we need a way to gather up the individual component devices
together, and indicate when we have all the component devices.
We do this in DT by providing a "superdevice" node which specifies
the components, eg:
imx-drm {
compatible = "fsl,drm";
crtcs = <&ipu1>;
connectors = <&hdmi>;
};
The superdevice is declared into the component support, along with the
subcomponents. The superdevice receives callbacks to locate the
subcomponents, and identify when all components are present. At this
point, we bind the superdevice, which causes the appropriate subsystem
to be initialised in the conventional way.
When any of the components or superdevice are removed from the system,
we unbind the superdevice, thereby taking the subsystem down.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-01-11 03:23:37 +04:00
mutex_unlock ( & component_mutex ) ;
WARN_ON ( ! component ) ;
kfree ( component ) ;
}
EXPORT_SYMBOL_GPL ( component_del ) ;
MODULE_LICENSE ( " GPL v2 " ) ;