{"id":241812,"date":"2022-05-10T10:08:23","date_gmt":"2022-05-10T02:08:23","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=241812"},"modified":"2022-05-04T19:09:36","modified_gmt":"2022-05-04T11:09:36","slug":"kernel-bus-architecture","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/kernel-bus-architecture.html","title":{"rendered":"\u5e26\u4f60\u4e86\u89e3\u4ec0\u4e48\u662f\u5185\u6838\u603b\u7ebf\u67b6\u6784"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5bf9\u4e8e\u5185\u6838\u603b\u7ebf\u6765\u8bf4\uff0c\u5927\u5bb6\u5e94\u8be5\u4f1a\u5bf9Platform\u603b\u7ebf\u6bd4\u8f83\u719f\u6089\uff0c\u77e5\u9053\u5728Platform\u603b\u7ebf\u4e0a\u4f1a\u6709\u4e24\u4e2a\u94fe\u8868\uff0c\u4e00\u6761\u94fe\u8868\u7528\u6765\u628a\u8be5\u603b\u7ebf\u4e0a\u7684\u6240\u6709\u8bbe\u5907\u94fe\u63a5\u8d77\u6765\uff0c\u4e00\u6761\u94fe\u8868\u7528\u6765\u628a\u8be5\u603b\u7ebf\u4e0a\u7684\u9a71\u52a8\u94fe\u63a5\u8d77\u6765\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5f53\u8bbe\u5907\u6216\u8005\u9a71\u52a8\u6dfb\u52a0\u5230\u94fe\u8868\u65f6\uff0c\u4f1a\u89e6\u53d1\u603b\u7ebf\u7684match\u51fd\u6570\u3002\u90a3\u4e48\uff0c\u60a8\u6709\u6ca1\u6709\u6df1\u5165\u53bb\u7814\u7a76\u8fc7\u5185\u6838\u603b\u7ebf\u5462?\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u6765\u6df1\u5165\u63a2\u8ba8\u4e00\u4e0b\u5185\u6838\u4e2d\u7684\u603b\u7ebf\uff0c\u4e3b\u8981\u6d89\u53ca\u5230\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n

\"\"<\/p>\n

businessman having questions and concrete wall<\/p>\n<\/div>\n

1.\u5185\u6838\u4e2d\u662f\u5982\u4f55\u90e8\u7f72\u603b\u7ebf\u7684\u3002
\n2.\u8bbe\u5907\u548c\u9a71\u52a8\u662f\u5982\u4f55\u6302\u8f7d\u5230\u603b\u7ebf\u4e0a\u7684\u3002
\n3.\u8bbe\u5907\u548c\u5176\u5bf9\u5e94\u7684\u9a71\u52a8\u662f\u5982\u4f55\u901a\u8fc7\u603b\u7ebf\u8fdb\u884c\u5339\u914d\u7684\u3002<\/p>\n

1.\u603b\u7ebf\u90e8\u7f72<\/strong><\/div>\n

\u6211\u4eec\u4ece\u51fd\u6570start_kernel\u6765\u5206\u6790\u603b\u7ebf\u7684\u90e8\u7f72\uff0c\u5b9e\u9645\u4e0a\u5728\u51fd\u6570start_kernel\u8c03\u7528\u4e4b\u524d\uff0c\u4f1a\u6709\u6c47\u7f16\u4ee3\u7801\u6765\u5904\u7406\u542f\u52a8\u53c2\u6570\uff0c\u542f\u52a8\u6a21\u5f0f\uff0c\u521b\u5efa\u5185\u6838\u7a7a\u95f4\u9875\u8868\uff0c\u51c6\u5907\u597d\u5806\u6808\u7b49\u3002\u7531\u4e8e\u8fd9\u4e9b\u540c\u603b\u7ebf\u90e8\u7f72\u5173\u7cfb\u4e0d\u5927\uff0c\u6682\u4e14\u5c31\u8ba4\u4e3astart_kernel\u5c31\u662f\u5185\u6838\u7684main\u51fd\u6570\u3002start_kernel\u5185\u90e8\u4f1a\u8c03\u7528rest_init\uff0crest_init\u51fd\u6570\u5185\u90e8\u521b\u5efa\u5185\u6838\u7ebf\u7a0bkernel_init\uff0c\u800ckernel_init\u4e2d\u6709\u5982\u4e0b\u7684\u51fd\u6570\u8c03\u7528\u8fc7\u7a0b\uff1a<\/p>\n

\r\nkernel_init-->do_basic_setup->driver_init\u2014>buses_init\u548cplatform_bus_init\r\n<\/pre>\n

\u6b64\u5904\u7684buses_init\u548cplatform_bus_init\u5c31\u662f\u603b\u7ebf\u7684\u90e8\u7f72\u51fd\u6570\uff0c\u4e5f\u662f\u672c\u5c0f\u8282\u7684\u91cd\u70b9\uff0c\u4e14buses_init\u5fc5\u987b\u5728platform_bus_init\u524d\u9762\u8c03\u7528\u3002\u56e0\u4e3aPlatform\u603b\u7ebf\u662f\u6302\u8f7d\u5728bus\u603b\u7ebf\u4e0b\u7684\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u8be6\u7ec6\u5206\u6790\u4e0b\u8fd9\u4e24\u4e2a\u8fc7\u7a0b\u3002<\/p>\n

buses_init<\/strong><\/span><\/div>\n

\u5185\u6838\u4e2d\u6240\u6709\u7684\u5bf9\u8c61\u5982bus\uff0c\u90fd\u662f\u4e00\u4e2akobject\uff0c\u800c\u628a\u76f8\u540c\u7c7b\u578b\u7684kobject\u96c6\u5408\u5230\u4e00\u8d77\u5c31\u7ec4\u6210\u4e86\u4e00\u4e2akset\uff0c\u800c\u51fd\u6570buses_init\u5185\u90e8\u5c31\u662f\u901a\u8fc7bus_kset = kset_create_and_add(\"bus\", &bus_uevent_ops, NULL)\u6765\u6ce8\u518cbus\u603b\u7ebf\u5bf9\u5e94\u7684kset\uff0c\u5176\u6700\u540ebus_kset\u5982\u4e0b\u56fe1\u6240\u793a\uff1a<\/p>\n

\"\"<\/p>\n

\u56fe 1 bus_kset\u7ed3\u6784<\/p>\n

\u81f3\u6b64\u7b97\u662f\u51c6\u5907\u597d\u4e86bus_kset\uff0c\u6211\u4eec\u7ee7\u7eed\u5f80\u4e0b\u770b\u4e00\u4e0b\u5176\u4ed6\u7c7b\u578b\u7684\u603b\u7ebf\u662f\u5982\u4f55\u548cbus\u8fdb\u884c\u5173\u8054\u7684\u3002<\/p>\n

platform_bus_init<\/strong><\/span><\/div>\n

\u8be5\u51fd\u6570\u4e3b\u8981\u5b8c\u6210\u4e24\u4e2a\u529f\u80fd\uff0c\u5176\u51fd\u6570\u5982\u4e0b\uff1a<\/p>\n

\r\nstruct bus_type platform_bus_type = {\r\n    .name       = \"platform\",\r\n    .dev_attrs  = platform_dev_attrs,\r\n    .match      = platform_match,\r\n    .uevent     = platform_uevent,\r\n    .pm     = &platform_dev_pm_ops,\r\n};\r\nEXPORT_SYMBOL_GPL(platform_bus_type);\r\nint __init platform_bus_init(void)\r\n{\r\n    int error;\r\n\r\n    early_platform_cleanup();\r\n\r\n    error = device_register(&platform_bus);\r\n    if (error)\r\n        return error;\r\n    error =  bus_register(&platform_bus_type);\r\n    if (error)\r\n        device_unregister(&platform_bus);\r\n    return error;\r\n}\r\n<\/pre>\n

device_register\u662f\u7528\u6765\u6ce8\u518c\u4e00\u4e2adevice\uff0c\u5e76\u6dfb\u52a0\u5230\u7cfb\u7edf\u4e2d\uff0c\u6700\u540e\u4f1a\u5728\/sys\/devices\/\u76ee\u5f55\u4e0b\u5efa\u7acb platform\u76ee\u5f55\u5bf9\u5e94\u7684\u8bbe\u5907\u5bf9\u8c61\uff0c\u5176\u8def\u5f84\u662f\/sys\/devices\/platform\/\u3002<\/p>\n

bus_register\u662f\u5c06Platform bus\u603b\u7ebf\u6ce8\u518c\u8fdb\u7cfb\u7edf\uff0c\u5176\u5b9e\u5185\u90e8\u5c31\u662f\u521b\u5efa\u4e86\u5bf9\u5e94\u7684kset\u548ckobject\u7b49\uff0c\u4e14\u4e3b\u8981\u5b8c\u6210\u4ee5\u4e0b\u4e09\u9879\u5de5\u4f5c\uff1a<\/p>\n

\u521d\u59cb\u5316\u5fc5\u987b\u7684\u7ed3\u6784\u4f53\uff0cstruct subsys_private \u548c\u5bf9\u5e94\u7684kobkect\u3002
\n\u540cbus\u603b\u7ebf\u5efa\u7acb\u5173\u7cfb\uff0ckobject.parent \u8bbe\u7f6e\u4e3a\u4e0a\u4e00\u6b65\u5df2\u7ecf\u521b\u5efa\u597d\u7684bus_kset.kobj, kobject.kset\u8bbe\u7f6e\u4e3abus_kset,\u628a\u5bf9\u5e94\u7684kobject.ktype\u8bbe\u7f6e\u4e3abus_ktype\u3002
\n\u628a\u5bf9\u5e94\u7684kobjet\u6dfb\u52a0\u5230\u5bf9\u5e94\u7684kset\u7684\u94fe\u8868\u4e2d\uff0c\u5bf9\u603b\u7ebf\u6765\u8bf4\uff0c\u5c31\u662f\u6dfb\u52a0\u5230bus_kset\u4e2d\u7684\u94fe\u8868\u4e2d\u3002
\n\u4e0b\u9762\u662fbus_register\u51fd\u6570\u7684\u5b9e\u73b0(\u5220\u9664\u4e86\u521b\u5efa\u5931\u8d25\u9000\u51fa\u65f6free\u5185\u5b58\u7b49\u7684\u64cd\u4f5c)\uff0c\u4e14\u6211\u5728\u4ee3\u7801\u4e2d\u589e\u52a0\u4e86\u6ce8\u91ca\uff0c\u65b9\u4fbf\u5927\u5bb6\u67e5\u9605\uff1a<\/p>\n

\r\n\/**\r\n * bus_register - register a bus with the system.\r\n * @bus: bus.\r\n *\r\n * Once we have that, we registered the bus with the kobject\r\n * infrastructure, then register the children subsystems it has:\r\n * the devices and drivers that belong to the bus.\r\n *\/\r\nint bus_register(struct bus_type *bus)\r\n{\r\n    int retval;\r\n    \/\/step:\u521b\u5efa\u5e76\u5206\u914d\uff0c\u521d\u59cb\u5316struct subsys_private\u7ed3\u6784\u4f53\u6307\u9488\r\n    struct subsys_private *priv;\r\n    priv = kzalloc(sizeof(struct subsys_private), GFP_KERNEL);\r\n    if (!priv)\r\n        return -ENOMEM;\r\n    priv->bus = bus;\r\n    bus->p = priv;\r\n    BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier);\r\n    retval = kobject_set_name(&priv->subsys.kobj, \"%s\", bus->name);\r\n    if (retval)\r\n        goto out;\r\n\r\n\/\/step2\uff1a\u540c\u4e0a\u9762\u521b\u5efa\u7684bus_kset\u8fdb\u884c\u5173\u8054\r\n\/\/kset_register\u65f6\uff0c\u4f1a\u8bbe\u7f6e\u5bf9\u5e94priv->subsys\u3002Kobject->parent = bus_kset.kobj\r\n    priv->subsys.kobj.kset = bus_kset;\r\n    priv->subsys.kobj.ktype = &bus_ktype;\r\n    priv->drivers_autoprobe = 1;\r\n    retval = kset_register(&priv->subsys); \/\/\u4e00\u4f1a\u6dfb\u52a0\u5230bus_kset\u94fe\u8868\u4e2d\r\n    if (retval)\r\n        goto out;\r\n    \/\/step3\uff1a\u521b\u5efa\u5bf9\u5e94\u7684\u5c5e\u6027\u6587\u4ef6\r\n    retval = bus_create_file(bus, &bus_attr_uevent);\r\n    if (retval)\r\n        goto bus_uevent_fail;\r\n\r\n    priv->devices_kset = kset_create_and_add(\"devices\", NULL,\r\n                         &priv->subsys.kobj);\r\n    if (!priv->devices_kset) {\r\n        retval = -ENOMEM;\r\n        goto bus_devices_fail;\r\n    }\r\n\r\n    priv->drivers_kset = kset_create_and_add(\"drivers\", NULL,\r\n                         &priv->subsys.kobj);\r\n    if (!priv->drivers_kset) {\r\n        retval = -ENOMEM;\r\n        goto bus_drivers_fail;\r\n    }\r\n    \/\/step4:\u521d\u59cb\u5316\u4e24\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u94fe\u8868\uff0c\u540e\u9762\u5185\u5bb9\u4e2d\u4f1a\u63d0\u5230\u8fd9\u4e24\u4e2a\u94fe\u8868\r\n    klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put);\r\n    klist_init(&priv->klist_drivers, NULL, NULL);\r\n    \r\n    \/\/step5:\u6dfb\u52a0\u63a2\u9488\u6587\u4ef6\r\n    retval = add_probe_files(bus);\r\n    if (retval)\r\n        goto bus_probe_files_fail;\r\n\r\n    retval = bus_add_attrs(bus);\r\n    if (retval)\r\n        goto bus_attrs_fail;\r\n\r\n    pr_debug(\"bus: '%s': registered\\n\", bus->name);\r\n    return 0;\r\n    \u2026\u2026\r\n    return retval;\r\n}\r\nEXPORT_SYMBOL_GPL(bus_register);\r\n<\/pre>\n

\u5bf9\u4e8e\u5176\u4ed6\u603b\u7ebf(\u5982IIC\u7b49)\uff0c\u4e5f\u662f\u901a\u8fc7bus_register\u8fdb\u884c\u6ce8\u518c\u7684\uff0c\u6bd4\u5982bus_register(&i2c_bus_type)\u548cbus_register(&mmc_bus_type)\u7b49\uff0c\u5176\u539f\u7406\u540c\u4e0a\u9762\u4e00\u6837\uff0c\u5728\u6b64\u5c31\u4e0d\u6328\u4e2a\u4ecb\u7ecd\u4e86\u3002<\/p>\n

\u901a\u8fc7\u4e0a\u9762\u7684\u5206\u6790\uff0c\u6211\u4eec\u77e5\u9053\u4e86bus\u603b\u7ebf\uff0c\u4e14\u5176\u4ed6\u603b\u7ebf\u6302\u8f7d\u5728bus\u603b\u7ebf\u4e0b\uff0c\u7b49\u603b\u7ebf\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u4e0d\u540c\u8bbe\u5907\u4f1a\u6302\u8f7d\u5728\u5bf9\u5e94\u7684\u603b\u7ebf\u4e0b\u9762\u3002\u5bf9\u4e8eSPI\uff0cIIC\u7b49\u8bbe\u5907\uff0c\u4ed6\u4eec\u90fd\u53ef\u4ee5\u6302\u8f7d\u5728\u5bf9\u5e94\u7684\u603b\u7ebf\u4e0b\u540cCPU\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\u3002\u4f46\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\uff0c\u6709\u4e9b\u8bbe\u5907\u662f\u4e0d\u5c5e\u4e8e\u8fd9\u4e9b\u5e38\u89c1\u7684\u603b\u7ebf\uff0c\u56e0\u6b64\u5f15\u5165\u4e86\u865a\u62df\u7684Platform\u603b\u7ebf\uff0c\u672c\u5c0f\u8282\u6b63\u662f\u901a\u8fc7\u865a\u62df\u7684Platform\u603b\u7ebf\u6765\u8bf4\u660e\u603b\u7ebf\u90e8\u7f72\u7684\u3002<\/p>\n

2.\u8bbe\u5907\u548c\u9a71\u52a8\u7684\u6302\u8f7d<\/strong><\/div>\n

\u6211\u4eec\u4f9d\u7136\u91c7\u7528Platform\u603b\u7ebf\u6765\u8bf4\u660e\u8bbe\u5907\u548c\u9a71\u52a8\u7684\u6302\u8f7d\u95ee\u9898\u3002<\/p>\n

\u8bbe\u5907\u6302\u8f7d<\/strong><\/span><\/div>\n

\u5bf9\u4e8ePlatform\u603b\u7ebf\u6765\u8bf4\uff0c\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570platform_device_register\u6765\u6302\u8f7d(\u6709\u7684\u5730\u65b9\u79f0\u4e4b\u4e3a\u6ce8\u518c)\u8bbe\u5907\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8bbe\u5907\u6811\u6765\u6302\u8f7d\uff0c\u5728\u5185\u6838\u542f\u52a8\u65f6\uff0c\u4f1a\u8fdb\u884c\u8bbe\u5907\u6811\u7684\u89e3\u6790\uff0c\u672c\u6587\u4e2d\u4e0d\u6d89\u53ca\u8bbe\u5907\u6811\uff0c\u4e3b\u8981\u4ecb\u7ecdplatform_device_register\u7684\u65b9\u5f0f\u3002<\/p>\n

\u8be5\u51fd\u6570\u539f\u578b\u5982\u4e0b\uff1a<\/p>\n

\r\nint platform_device_register(struct platform_device *pdev)\r\n{\r\n    device_initialize(&pdev->dev);\r\n    return platform_device_add(pdev);\r\n}\r\n<\/pre>\n

\u51fd\u6570\u5728\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6709\u5982\u4e0b\u8c03\u7528\u5173\u7cfb\uff1a<\/p>\n

platform_device_add---->\u8bbe\u7f6estruct platform_device\u4e2d\u7684\u603b\u7ebf\u7c7b\u578b\u53ca\u5176\u4ed6\u53c2\u6570--->device_add--->bus_add_device---->klist_add_tail<\/p>\n

\u8fd9\u4e2a\u8c03\u7528\u8fc7\u7a0b\u7701\u7565\u4e86\u4e00\u4e9b\u5c5e\u6027\u548c\u8282\u70b9\u7b49\u7684\u5904\u7406\uff0c\u6211\u5173\u6ce8\u7684\u91cd\u70b9\u5728\u51fd\u6570klist_add_tail\uff0c\u8be5\u51fd\u6570\u662f\u628a\u5f53\u524d\u8bbe\u5907\u6dfb\u52a0\u5230platform_bus\u4e2d\u7684\u4e00\u4e2a\u94fe\u8868\u4e2d\uff0c\u8fd9\u4e2a\u94fe\u8868\u5728Platform\u603b\u7ebf\u90e8\u7f72\u65f6\u5c31\u521d\u59cb\u5316\u5b8c\u6210\u4e86\uff0c\u5176\u521d\u59cb\u5316\u51fd\u6570\u5c31\u662f\u51fd\u6570bus_register\u4e2d\u7684step4\uff0c\u53ef\u4ee5\u7ffb\u9605\u4e0a\u4e00\u4e2a\u5c0f\u8282\u6765\u67e5\u770b\u3002<\/p>\n

\u9a71\u52a8\u6302\u8f7d<\/strong><\/span><\/div>\n

\u5bf9\u4e8ePlatform\u603b\u7ebf\u6765\u8bf4\uff0c\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570platform_driver_register\u6765\u6302\u8f7d(\u6709\u7684\u5730\u65b9\u79f0\u4e4b\u4e3a\u6ce8\u518c)\u8bbe\u5907\uff0c\u5176\u51fd\u6570\u539f\u578b\u5982\u4e0b\uff1a<\/p>\n

\r\nint platform_driver_register(struct platform_driver *drv)\r\n{\r\n    drv->driver.bus = &platform_bus_type;\r\n    if (drv->probe)\r\n        drv->driver.probe = platform_drv_probe;\r\n    if (drv->remove)\r\n        drv->driver.remove = platform_drv_remove;\r\n    if (drv->shutdown)\r\n        drv->driver.shutdown = platform_drv_shutdown;\r\n\r\n    return driver_register(&drv->driver);\r\n}\r\nEXPORT_SYMBOL_GPL(platform_driver_register);\r\n<\/pre>\n

\u51fd\u6570\u5728\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6709\u5982\u4e0b\u8c03\u7528\u5173\u7cfb\uff1a<\/p>\n

driver_register---> \u8bbe\u7f6e\u5bf9\u5e94\u7684\u53c2\u6570\u7b49---->driver_find---> bus_add_driver----> klist_add_tail<\/p>\n

\u76f8\u5bf9\u4e8e\u8bbe\u5907\u6302\u8f7d\uff0c\u591a\u4e86\u4e00\u4e2a\u51fd\u6570driver_find\u7684\u8c03\u7528\uff0c\u8be5\u51fd\u6570\u4e3b\u8981\u76ee\u7684\u5c31\u662f\u5224\u65ad\u9a71\u52a8\u662f\u5426\u5df2\u7ecf\u6302\u8f7d\u4e0a\u4e86\uff0c\u5176\u4f59\u5904\u7406\u65b9\u5f0f\u540c\u8bbe\u5907\u6302\u8f7d\u76f8\u540c\u3002\u6700\u4e3a\u91cd\u8981\u7684\u4f9d\u7136\u662fklist_add_tail\uff0c\u628a\u8be5\u9a71\u52a8\u6dfb\u52a0\u5230\u4e86platform_bus\u4e2d\u7684\u4e00\u4e2a\u94fe\u8868\u4e2d\u3002<\/p>\n

\u5176\u4ed6\u7c7b\u578b\u7684\u603b\u7ebf\u8bbe\u5907\u548c\u9a71\u52a8\u76f8\u540c\uff0c\u4e5f\u4f1a\u5b58\u5728\u4e24\u4e2a\u94fe\u8868\uff0c\u8bbe\u5907\u548c\u9a71\u52a8\u5747\u6302\u8f7d\u5230\u76f8\u5e94\u7684\u94fe\u8868\u4e2d\u3002<\/p>\n

3.\u8bbe\u5907\u548c\u9a71\u52a8\u7684\u5339\u914d<\/strong><\/div>\n

\u4ece\u7b2c2\u5c0f\u8282\u4e2d\uff0c\u6211\u4eec\u77e5\u9053Platform\u603b\u7ebf\u4e0b\u6709\u4e24\u4e2a\u94fe\u8868\uff0c\u6211\u91c7\u7528\u4e0b\u9762\u7684\u56fe\u6765\u5177\u4f53\u5316\u8fd9\u4e24\u4e2a\u94fe\u8868\uff0c\u56fe\u5de6\u8fb9\u7684\u8bbe\u5907\u94fe\u8868\uff0c\u56fe\u4e2d\u4ec5\u5448\u73b03\u4e2a\u8bbe\u5907\uff0c\u5b9e\u9645\u4e0a\u4f1a\u6709\u5f88\u591a\uff0c\u56fe\u53f3\u8fb9\u4e3a\u9a71\u52a8\u94fe\u8868\u3002\u4e0d\u7ba1\u662f\u5de6\u8fb9\u7684\u8bbe\u5907\u8fd8\u662f\u53f3\u8fb9\u7684\u9a71\u52a8\uff0c\u5747\u6709name\u5b57\u6bb5(\u901a\u5e38\u60c5\u51b5\u4e0b\u662fcompatible)\uff0c\u8fd9\u662f\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u5b57\u6bb5\uff0c\u540e\u9762\u6211\u4eec\u4f1a\u7528\u5230\u5b83\u3002<\/p>\n

\"\"<\/p>\n

\u56fe 2Platform\u603b\u7ebf\u7684\u4e24\u4e2a\u94fe\u8868<\/p>\n

\u9488\u5bf9\u5339\u914d\u95ee\u9898\uff0c\u6211\u4f9d\u7136\u91c7\u7528Platform\u603b\u7ebf\u6765\u9610\u8ff0\uff0c\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u5728\u8fdb\u884c\u9a71\u52a8\u6302\u8f7d\u65f6\uff0c\u4f1a\u8c03\u7528\u51fd\u6570bus_add_driver\uff0c\u8be5\u51fd\u6570\u5185\u6838\u5b9e\u9645\u4e0a\u8fd8\u4f1a\u8c03\u7528\u4e00\u4e2a\u51fd\u6570driver_attach(\u9488\u5bf9\u8bbe\u7f6edrivers_autoprobe\u7684\u60c5\u51b5)\uff0c\u4e0b\u9762\u662f\u51fd\u6570driver_attach\u7684\u8c03\u7528\u60c5\u51b5\uff1a<\/p>\n

\r\ndriver_attach\r\n--->bus_for_each_dev(drv->bus, NULL, drv, __driver_attach)\r\n---> klist_iter_init_node(&bus->p->klist_devices, &i, (start ? &start->p->knode_bus : NULL));\r\n   while ((dev = next_device(&i)) && !error)\r\n      error = fn(dev, data);\r\n   --->driver_match_device\r\n     ---> drv->bus->match\r\n       ---> platform_match\r\n<\/pre>\n

\u4ece\u4e0a\u9762\u4ee3\u7801\u8fc7\u7a0b\u53ef\u4ee5\u770b\u51fa\uff0c\u5f53\u6302\u8f7d\u9a71\u52a8\u65f6\uff0c\u4f1a\u904d\u5386\u56fe2\u4e2d\u5de6\u8fb9\u7684\u94fe\u8868\uff0c\u6700\u540e\u8c03\u7528Platform\u603b\u7ebf\u7684match\u51fd\u6570platform_match (match\u51fd\u6570\u662f\u5728struct bus_type platform_bus_type\u4e2d\u8bbe\u7f6e\u7684\uff0c\u5728\u603b\u7ebf\u90e8\u7f72\u65f6\u9636\u6bb5\u8c03\u7528platform_bus_init\u5c31\u8bbe\u7f6e\u597d\u4e86)\u6765\u8fdb\u884c\u8bbe\u5907\u548c\u9a71\u52a8\u7684\u5339\u914d\u3002\u6bcf\u4e2a\u603b\u7ebf\u90fd\u4f1a\u6709\u81ea\u5df1\u7684match\u51fd\u6570\uff0c\u4e14match\u51fd\u6570\u91cc\u9762\u4f1a\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5339\u914d\uff0c\u5982\u5e38\u89c1\u7684compitable\uff0cname\u6216\u8005id_table\uff0c\u53ea\u8981\u6709\u4e00\u4e2a\u80fd\u5339\u914d\u4e0a\uff0c\u5219\u8ba4\u4e3a\u9a71\u52a8\u548c\u8bbe\u5907\u5339\u914d\u6210\u529f\u3002<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u672c\u6587\u4e3b\u8981\u91c7\u7528Platform\u6765\u8bf4\u660e\u4e86\u5185\u6838\u4e2d\u603b\u7ebf\u90e8\u7f72\uff0c\u8bbe\u5907\u548c\u9a71\u52a8\u6302\u8f7d\uff0c\u53ca\u8bbe\u5907\u548c\u9a71\u52a8\u7684\u5339\u914d\u95ee\u9898\uff0c\u5b9e\u9645\u4e0a\u5176\u4ed6\u603b\u7ebf\u4e5f\u662f\u91c7\u7528\u76f8\u540c\u7684\u65b9\u5f0f\uff0c\u5728\u6211\u7684\u63cf\u8ff0\u8fc7\u7a0b\u4e2d\uff0c\u91cd\u70b9\u5728\u4e8e\u603b\u7ebf\uff0c\u5ffd\u7565\u4e86\u4e00\u4e9bsysfs\u8282\u70b9\uff0c\u5f15\u7528\u8ba1\u6570\uff0ckobject\uff0ckset\u7b49\uff0c\u4f46\u8fd9\u4e9b\u5728\u5185\u6838\u67b6\u6784\u4e2d\u4e5f\u662f\u6bd4\u8f83\u91cd\u8981\u7684\u73af\u8282\uff0c\u5e0c\u671b\u5927\u5bb6\u5728\u4e86\u89e3\u603b\u7ebf\u67b6\u6784\u540e\uff0c\u4e5f\u80fd\u6709\u65f6\u95f4\u53bb\u6df1\u5165\u67e5\u770b\u5185\u6838\u603b\u7ebf\u7684\u5404\u4e2a\u5904\u7406\u7ec6\u8282\u3002<\/p>\n

\u7279\u522b\u8bf4\u660e\uff1a\u4e0d\u540c\u7684\u5185\u6838\uff0c\u53ef\u80fd\u4f7f\u7528\u5230\u7684\u51fd\u6570\uff0c\u6216\u8005\u51fd\u6570\u7684\u5b9e\u73b0\u540c\u6587\u7ae0\u4e2d\u4ecb\u7ecd\u7684\u5b58\u5728\u51fa\u5165\uff0c\u4f46\u5176\u539f\u7406\u53ca\u67b6\u6784\u76f8\u540c\uff0c\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u8003\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5f53\u8bbe\u5907\u6216\u8005\u9a71\u52a8\u6dfb\u52a0\u5230\u94fe\u8868\u65f6\uff0c\u4f1a\u89e6\u53d1\u603b\u7ebf\u7684match\u51fd\u6570\u3002\u90a3\u4e48\uff0c\u60a8\u6709\u6ca1\u6709\u6df1\u5165\u53bb\u7814\u7a76\u8fc7\u5185\u6838\u603b\u7ebf\u5462?\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u6765 […]<\/p>\n","protected":false},"author":1898,"featured_media":241817,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[849],"class_list":["post-241812","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-849"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/241812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=241812"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/241812\/revisions"}],"predecessor-version":[{"id":241816,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/241812\/revisions\/241816"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/241817"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=241812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=241812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=241812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}