/**dir: driver/base/Platform.c
* platform_match - bind platform device to platform driver.
* @dev: device.
* @drv: driver.
*
* Platform device IDs are assumed to be encoded like this:
* "<name><instance>", where <name> is a short description of the type of
* device, like "pci" or "floppy", and <instance> is the enumerated
* instance of the device, like '0' or '42'. Driver IDs are simply
* "<name>". So, extract the <name> from the platform_device structure,
* and compare it against the name of the driver. Return whether they match
* or not.
*/
static int platform_match(struct device *dev, struct device_driver *drv)
{
//已知struct device和struct device_driver结构指针,要找到包含它们的父指针struct platform_device和platform_driver.
struct platform_device *pdev = to_platform_device(dev);//container_of((x), struct platform_device, dev)
struct platform_driver *pdrv = to_platform_driver(drv);//container_of((drv), struct platform_driver,driver))
/* Attempt an OF style match first */
if (of_driver_match_device(dev, drv))
return 1;
/* Then try to match against the id table */
if (pdrv->id_table)
return platform_match_id(pdrv->id_table, pdev) != NULL;
/* fall-back to driver name match */
return (strcmp(pdev->name, drv->name) == 0);
}
/**container_of - Macro in Kernel.h (tools\perf\util\include\linux) at line 26 (3 lines)
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
const typeof(((type *)0)->member) * __mptr = (ptr); \/*typeof(x)表示获取x参数的类型*/
(type *)((char *)__mptr - offsetof(type, member)); })