From patchwork Thu Apr 26 11:26:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10365645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 36400602DC for ; Thu, 26 Apr 2018 11:27:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 254652906A for ; Thu, 26 Apr 2018 11:27:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 194AB29089; Thu, 26 Apr 2018 11:27:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 898F32906A for ; Thu, 26 Apr 2018 11:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755385AbeDZL11 (ORCPT ); Thu, 26 Apr 2018 07:27:27 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:33061 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754905AbeDZL1N (ORCPT ); Thu, 26 Apr 2018 07:27:13 -0400 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie1.idc.renesas.com with ESMTP; 26 Apr 2018 20:27:10 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id 4338276C04; Thu, 26 Apr 2018 20:27:10 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.49,330,1520866800"; d="scan'208";a="277957258" Received: from mail-ty1jpn01lp0179.outbound.protection.outlook.com (HELO JPN01-TY1-obe.outbound.protection.outlook.com) ([23.103.139.179]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 26 Apr 2018 20:27:10 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=sYPlSsyfHU+ApvixOnlZYauXSFl9nlt0bUWvfu4KG6Q=; b=m5I5EbiCHQ0LeCBz8WnRh3SQOSJiS+Dw09kMmojoYPOKd8VaN04EnmtKtPq9vpW795FWprEAJpbbPWi+kgQTJOwWHPFLPyz2OfpxA74LeJYzZMMvU2mkoom3+pjjxPjBnx9HQLtwT6MMuFewn8EypEAZC0ou85A6yS06O2/K3qY= Received: from localhost.localdomain (211.11.155.138) by TYAPR01MB2304.jpnprd01.prod.outlook.com (2603:1096:404:8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Thu, 26 Apr 2018 11:27:07 +0000 From: Yoshihiro Shimoda To: gregkh@linuxfoundation.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: heikki.krogerus@linux.intel.com, hdegoede@redhat.com, andy.shevchenko@gmail.com, linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH/RFC v2 2/6] base: devcon: add a new API to find the graph Date: Thu, 26 Apr 2018 20:26:42 +0900 Message-Id: <1524742006-17984-3-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524742006-17984-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1524742006-17984-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: OSAPR01CA0066.jpnprd01.prod.outlook.com (2603:1096:604:a::30) To TYAPR01MB2304.jpnprd01.prod.outlook.com (2603:1096:404:8::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4534165)(4627221)(201703031133081)(8559017)(2017052603328)(7153060)(7193020); SRVR:TYAPR01MB2304; X-Microsoft-Exchange-Diagnostics: 1; TYAPR01MB2304; 3:SOhvgUuNFbTyfq1BlD722ALglzxncc4BYYWoQPDYWrxOyr7RxPaxnitw0X5xM0RyRxuxkOxyeKkZBUUvoxG7M1rEgQcRpQc5v/IGod680GmVE+P+VPR+S/1PQDOtEUIWMEYn/iJ+ennv+h46bQPUPCS3eUEJHyANdctsxnA3fWKTD0OsnHm0BgMiOohFS8+0q+NgJq7ux0dMbadHILQP2I7q3ztx8m2rQRJxtZ2XhkQUbciuThhjsk/7oyOZNB4j; 25:uP78xGIJwLkuATiunpBfTzwl3MLhljzx61LLu6WhVmHbF/MZNRcWMobFHoPMuhPKD7TWyrjUukLJt7Wdr02EUwYyS80X9wcmnGFUIRCLP3/MQ0rTzf5yNfympOG6yCfREk+9DnhBKiV6ecB1x8Qao9VnqHjC0MOIDBkwMDMtJGoNeCHK0TAWlASKuEv8HfNArmWQKsvYgmmivadvR6cCK0zCY2CGKg2z3Jsue/DswBQHYzecI5Flevqlmo4KEN/QtAchBIkDCN7JYUYxe+jXFh2rCdnoNt+F450NWXQ7EI7xEP5ULf5GlOG/F7qtS2c2/FEzRakXtQU0BcbZuyjjTQ==; 31:eNdnITqrCT6PsS8X4PjN4QaE8EOR5dptjYxbMSRiMdX5aaugdYK7mRmpzmOapEMNHUbHLvWQHfUpIHNrGRe5m1zEgmqZg+lwkVoz60cjvUE9e/hIf1MNRQv+d5h3eKKgqIn5APDnM6TBw/+AFiDm94lrT2qzOmrEKFnyxZAcrZT9oexWjR6QYjC7BqRsUluHtnVSYrGW1RQVOfwdxqIuIa5xihn9gxcjbVBH/VtN4cI= X-MS-TrafficTypeDiagnostic: TYAPR01MB2304: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; X-Microsoft-Exchange-Diagnostics: 1; TYAPR01MB2304; 20:e/CLUuxGEehMYTmqzCcLCUwT0+duE9LM1pkuIY2wcLE6mHG5DWRyy6FGY2fzswF+5EMjBSKw44j/cJb/y1zm/IaC9nOBHK0lmkcbPJemQMKf3qazdCg9TpP4gP92cVvXnWY0hMYgCY6m/Tg0otm0K0wMb6uphcpgdzVrb++aOLYrFJAv5AsfJbgRNoIao+1ScHqdJ6SbshujpJHn4KhmrP6eDLrjaP3OQeCqMQBGFfnq/6YrT1L61FznAHPmT/Zt9DKJWrFH8C1nCBq9xmPFFTW7rgv/vm+ohQaozPBZg60GTtLCpw9Jx2FU/SybzrVmLjX2S7Lw42EsFw1lSiN5Ltbb40jQJ5FolvF9uiBlse+whWclPRyyAsyGkURj//nKedC65UC7eO/4DwQX69Bk0a5iAwBhjvlg/Y/FDdvjbrn2g5MqT4wWZAXGk1bhvxWyDAHB8RDg9KzZZW4s0JE/xCcdoq3N4lj/Wk6E7dIT5k0tqcMMZqEVuOa4Yx+oZeEW; 4:myzpG1oUNAaqdC54KakhqJJAXS+MiTHuZR0gVVP9CpNe936WoDnHyjBna9/hJDRTPbdYf7YGCo5ttGe+eV8X30x5F8nXeIBqa+LInzvXo4lF3r+vyXjc+NHrxZ06CiT0agv4Duik+nH+l30FviWSJ2FsRrjtEY8/Y66Fddc1c3SV48PkQXDZ6n2PHGyaLTen3bjQBzmAg/64u543C9P75s4dPzbvZ/GcyPWcVCVIJT3QsknVCBkRopRv6kaOAelciVrr3dXN1SPmZINZjssv2g== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231232)(944501410)(52105095)(93006095)(10201501046)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:TYAPR01MB2304; BCL:0; PCL:0; RULEID:; SRVR:TYAPR01MB2304; X-Forefront-PRVS: 0654257CF5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(346002)(39380400002)(376002)(39860400002)(396003)(366004)(189003)(199004)(25786009)(48376002)(386003)(81166006)(6506007)(106356001)(316002)(16526019)(305945005)(50466002)(42882007)(26005)(16586007)(51416003)(52116002)(8936002)(81156014)(8676002)(50226002)(575784001)(11346002)(53936002)(6666003)(78352004)(476003)(486006)(2616005)(446003)(7736002)(59450400001)(956004)(6486002)(6512007)(97736004)(2906002)(66066001)(6116002)(39060400002)(107886003)(3846002)(5660300001)(105586002)(4326008)(47776003)(498600001)(68736007)(36756003)(76176011)(37363001)(3720700003); DIR:OUT; SFP:1102; SCL:1; SRVR:TYAPR01MB2304; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:0; A:0; Received-SPF: None (protection.outlook.com: localhost.localdomain does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; TYAPR01MB2304; 23:+jUVv6IpkFNmwbq/r5pKEoN4VkhA8Lz3M3VRPevUM?= =?us-ascii?Q?h5eqiZdXR+RuCWL0nojY9YyNzRv1vhd8nA8vcJ3c/PQLHylB/mauI2d8oiH3?= =?us-ascii?Q?XrH4pHVilp6ufb0OUKjCF3D5rKJZUPasb9Su9HUqCbkLLYMMoX99Ywvdjojz?= =?us-ascii?Q?uQI3jza2EsydvUs9WY9mih5CKXqjIXqYE1G1BoyHYzyxReQ91+to/dgR9lFD?= =?us-ascii?Q?wymRpE4wVtne+9C6pBpJCpqc2Pysaxxb23f4xCO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021kKqjUF59SWV8ceicGfIjP35PV1gsAOi8lyGyH7c1bPonax6qUhIeDKrn0v+g=; 24:UI2+ghHQVmFbIdxCU/b8vqVF8KSoOnyJ+dKx89TvSnZB0Aisk0TKduhfx/SEpm9oE00dDxud/eQKV5vEVNCI2zl4xo1VCMTDmsWxqtdL8tI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; TYAPR01MB2304; 7:ocCp/T5pnXyKrPr1V9tPQrgGV6BHMOMp/h24nnSQopj8tOTaIoydIHjd/9ywZJ6WV0GUU0nJ54ASHszG89SehoJerMU6faegLvMDuYo8oK0ihaBjg8kvSyWfLRIs9lXsdZ8QYyEGMueVTtkkYK++zmwTgSwwRjHY6PzPiJgx3bZWoTLZCLSNWeqjT1iigIv5R+Yrr5UTot0kQPxmyVmIuTR23mD3+oT1PBORx5IUV/b5Z0XtY2nmimLtt/ZLWsd3; 20:bhH7Zq/f8goBWpxC4ZAaC2OlvN+cwxzBIAr64V5X65fgvyDyV0P19ZNd++cx0m8xSp/ciTe9ciy55EIWWzgNxm+X9s7mVoEPxCl9lp4+UL91i8c5R1GEVAjimGKEkuAZuf5n7T4GFKORb7+6Nm30BV0GILo5GZPNVxfVv7e/f4w= X-MS-Office365-Filtering-Correlation-Id: 1c42a9d2-ea14-4e5b-1865-08d5ab68a521 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2018 11:27:07.5026 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c42a9d2-ea14-4e5b-1865-08d5ab68a521 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYAPR01MB2304 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a new API "device_connection_find_by_graph()" to find device connection by using graph. Signed-off-by: Yoshihiro Shimoda --- Documentation/driver-api/device_connection.rst | 4 +-- drivers/base/devcon.c | 43 ++++++++++++++++++++++++++ include/linux/device.h | 2 ++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Documentation/driver-api/device_connection.rst b/Documentation/driver-api/device_connection.rst index affbc556..2e2d26f 100644 --- a/Documentation/driver-api/device_connection.rst +++ b/Documentation/driver-api/device_connection.rst @@ -19,7 +19,7 @@ Device connections alone do not create a dependency between the two devices. They are only descriptions which are not tied to either of the devices directly. A dependency between the two devices exists only if one of the two endpoint devices requests a reference to the other. The descriptions themselves can be -defined in firmware (not yet supported) or they can be built-in. +defined in firmware or they can be built-in. Usage ----- @@ -40,4 +40,4 @@ API --- .. kernel-doc:: drivers/base/devcon.c - : functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove + : functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove device_connection_find_by_graph diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c index d427e80..5a0da33 100644 --- a/drivers/base/devcon.c +++ b/drivers/base/devcon.c @@ -7,6 +7,7 @@ */ #include +#include static DEFINE_MUTEX(devcon_lock); static LIST_HEAD(devcon_list); @@ -134,3 +135,45 @@ void device_connection_remove(struct device_connection *con) mutex_unlock(&devcon_lock); } EXPORT_SYMBOL_GPL(device_connection_remove); + +static int generic_graph_match(struct device *dev, void *fwnode) +{ + return dev->fwnode == fwnode; +} + +/** + * device_connection_find_by_graph - Find two devices connected together + * @dev: Device to find connected device + * @port: identifier of the @dev port node + * @endpoint: identifier of the @dev endpoint node + * + * Find a connection with @port and @endpoint by using graph between @dev and + * another device. On success returns handle to the device that is connected + * to @dev, with the reference count for the found device incremented. Returns + * NULL if no matching connection was found, or ERR_PTR(-EPROBE_DEFER) when + * a connection was found but the other device has not been enumerated yet. + */ +struct device *device_connection_find_by_graph(struct device *dev, u32 port, + u32 endpoint) +{ + struct bus_type *bus; + struct fwnode_handle *remote; + struct device *conn; + + remote = fwnode_graph_get_remote_node(dev_fwnode(dev), port, endpoint); + if (!remote) + return NULL; + + for (bus = generic_match_buses[0]; bus; bus++) { + conn = bus_find_device(bus, NULL, remote, generic_graph_match); + if (conn) + return conn; + } + + /* + * We only get called if a connection was found, tell the caller to + * wait for the other device to show up. + */ + return ERR_PTR(-EPROBE_DEFER); +} +EXPORT_SYMBOL_GPL(device_connection_find_by_graph); diff --git a/include/linux/device.h b/include/linux/device.h index 0059b99..58f8544 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -751,6 +751,8 @@ void *device_connection_find_match(struct device *dev, const char *con_id, void device_connection_add(struct device_connection *con); void device_connection_remove(struct device_connection *con); +struct device *device_connection_find_by_graph(struct device *dev, u32 port, + u32 endpoint); /** * enum device_link_state - Device link states.