From patchwork Mon May 14 09:15:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10397639 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 21EC0601E7 for ; Mon, 14 May 2018 09:17:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C11D290DB for ; Mon, 14 May 2018 09:17:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3411290DE; Mon, 14 May 2018 09:17:07 +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 CEEAB290DA for ; Mon, 14 May 2018 09:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752319AbeENJRC (ORCPT ); Mon, 14 May 2018 05:17:02 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:34265 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751962AbeENJQn (ORCPT ); Mon, 14 May 2018 05:16:43 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie1.idc.renesas.com with ESMTP; 14 May 2018 18:16:41 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 4C4E182D7E; Mon, 14 May 2018 18:16:41 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.49,399,1520866800"; d="scan'208";a="280916055" Received: from mail-ty1jpn01lp0179.outbound.protection.outlook.com (HELO JPN01-TY1-obe.outbound.protection.outlook.com) ([23.103.139.179]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 14 May 2018 18:16:40 +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=gfcIfIKYXcvrANzcSD4e81zBMwhYH+U6m5Sv+ame8t4bOldz8mh88n0IntVlYuM6r7nTok2h2/1RKyMTWye+pgurn3gMcEOTx1Ml0Urw+26FRD/O7cEmAdkoySSwr7n+uWN80+gaR2Ju9KmVyt/ZufU2ESboeXyTtqVmL9jSkaE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost.localdomain (211.11.155.138) by OSBPR01MB2293.jpnprd01.prod.outlook.com (2603:1096:603:26::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Mon, 14 May 2018 09:16:38 +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 v3 1/4] base: devcon: add a new API to find the graph Date: Mon, 14 May 2018 18:15:57 +0900 Message-Id: <1526289360-3997-2-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526289360-3997-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1526289360-3997-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: TY1PR01CA0144.jpnprd01.prod.outlook.com (2603:1096:402:1::20) To OSBPR01MB2293.jpnprd01.prod.outlook.com (2603:1096:603:26::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(5600026)(2017052603328)(7153060)(7193020); SRVR:OSBPR01MB2293; X-Microsoft-Exchange-Diagnostics: 1; OSBPR01MB2293; 3:FYS4Hs4N1aRSuEJZ+RdaVmq9ySU0Llbn18vP5BTL2KZzzuQgofOYr2PWUVLi/H2WKtjzEfEDxHYIqRQKLvIVXMHVU/5iJB+3tIJzjnjGpIFIf4zCTXfshcgXX/nh8kn1qtNPIZm2DO6S7NeUrHOXVAZsFdKbZJ8OMTs08JZ43HnavfDcMmTLACRLMGKIDjIQyX4il3lecYKxcqbKcTIRUNxS+AT6F9jzM6t2PkCqPiwkq+lwarYNdhZ91nqLowvX; 25:0YT6WkDfvaLNQF5JdP741tGSKQwrE68766Qrl9s5h5mh3WmeiSEFk4mgfJqDCHQbUP0d2/ybjwt1j7jAwG9sI7HXaavRNFv59oyJZMySKlSdGGcPFVx4qHKvlPVhX7jbpyITKNFYWneJtvHNkeVjH4v2qtvUEPkkyPJEuchIXrYd7PpCNGFw6ak0itgePqDM0vRmqScNV2XnhwGRst04Bk5X4ugu4TitpI4kH68+wjtdbEappyyeDoFQmrFiMTbwtjnIb0UWFMtue6V6MNwRvQd7oAZSMdBijech/maiXjvyD4MSrZJhrt+czIq5g+AZDAgdpT+XphhcdFDTuVAs2w==; 31:dK+/FprRIXj6MqqanoR4m/tfiDN0gKee2DBqLKdunUZdkNPiua6UAQgUNn5o21eIWHYbJn58Lg6gtV60lqdQ9cCHuKNqY1xKwX6/DPH8urPVTEJclzUudXmZZSW1r5Ny0sGP7JMymbT0a2K/ljP8/r+0t0sJUJHvD4VLkHjMu1NbXakHMngFAMcjp05j+RVteLBkXyrSn4lwRsEIATGEHD5kz95S6iLRok6r/M2HxNk= X-MS-TrafficTypeDiagnostic: OSBPR01MB2293: X-Microsoft-Exchange-Diagnostics: 1; OSBPR01MB2293; 20:ySp6hjlTdgnANEarL1p9e6rRhHsXyweRPyHxeK0uZYin3erlEKGdDUSiR8nIO9oYjhgvrY3c9xGRukJQ0VO6+UV7mVUdHfPlqVoLOsqm+N7F1fyKNFVKoXG6pnyTibxVURG4L8RVtrDDajLvwz8ZU+yNqPLjzI7sVUjK3r8/0f0WiMXAfoiJZE+RhPYWHFe9LTxa1SiQUuIrAtw7OUDW3hZQ+86Z1RkInn/jFxLOxFLCES/PgPmgTOdltIVZaKtLRCWvKOPPu/bdzA51O2NJ1KNCSwo9c5zxL7OBYjamKnY8EmwrQvd8w7DaiXVcHxB3LxeaFST/g6XDBDgc/2Kccv1Fckh3w3gGuySufzU/NdjnMgj2eWhVYJx+V8k4+7U1hUSZOJd/b1TeR0vfG1rlfdR6LoFTWtVedMdj3BBpXiIXHtJ+M/bsUI57cxEToSHDrUIi2RUGOKBjDDhhCtYJ1vvrGNFQfUjDJyUGorEQDWv0RyiPFKhiTh92M9ChHle8; 4:yRtP/pj+kjX78UgJYVuGOQ7+7CQufvbUMINFqXLoj99lKCYG+Yuz0mqcB8iMnyuXBVSIHVX4hzvcFQqZKjws+NJon8SAalB2ivIdMe0Alrb1lOhHy4g/0A2o4sk2TfwkH+VH/ritfxagkcMoedllfWutv7OlLjQ1pg6LkXt/4HyKfWioTpfGm1e0JR/jGHABF7RKqGlsUEJcXeEEXXteo9RDaKT5Md3jXlacHAy5Z0D9zqTlY3IS9T5hVyv7cZ+FmcMK3WFRsSFmFRpy7OyQTA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(6072148)(201708071742011); SRVR:OSBPR01MB2293; BCL:0; PCL:0; RULEID:; SRVR:OSBPR01MB2293; X-Forefront-PRVS: 067270ECAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(346002)(376002)(39380400002)(39860400002)(396003)(366004)(199004)(189003)(16526019)(107886003)(68736007)(97736004)(53936002)(36756003)(50466002)(4326008)(6512007)(316002)(6116002)(106356001)(6486002)(6506007)(386003)(16586007)(575784001)(26005)(3846002)(25786009)(59450400001)(5660300001)(78352004)(47776003)(81166006)(7736002)(52116002)(81156014)(305945005)(50226002)(2906002)(51416003)(105586002)(39060400002)(11346002)(486006)(42882007)(2616005)(446003)(48376002)(476003)(6666003)(498600001)(956004)(76176011)(66066001)(8676002)(8936002)(37363001)(3720700003); DIR:OUT; SFP:1102; SCL:1; SRVR:OSBPR01MB2293; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:0; Received-SPF: None (protection.outlook.com: localhost.localdomain does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; OSBPR01MB2293; 23:2FKTxwHFwpbVRwh23r8KmxGnQVkiGifm/85KMW4Vv?= =?us-ascii?Q?VLWEoZANxF7iGFCtSdhIICpfYwQDldAPyyheEEGQXdM1GP5VDXv5TwhARKCs?= =?us-ascii?Q?AQoy9SPtVVjtdT7EVcc7pvNwI1Eslkzj8RX1tpmPOhWhmlhrenTBF2TgIfm1?= =?us-ascii?Q?0DbJE//ubUCn5OoqeCtGP8vWXHLghoPyZwCOr/49vI0x/zLkQlRVK4IHeOag?= =?us-ascii?Q?EaJh/eNFCywHnsq4syf3V6UAW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acACw2Tm69OBxTmMZiNu5QXQbTixwIMrwu6i3shoZSiU2DG/lpOmyfHHme+1VtXTufSCYvG6W21gnY=; 24:r9r6WWipeHIGfCzMazv3AP5QnBRV198Sd23erDOOwjeWiT52feWTtxDmJxmYhwbBeQp8diy2hcnvTnkWYd7kF/SfBgeg5c6o3k1RrPp/LBM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; OSBPR01MB2293; 7:7lti3G4iT2ErNmb8xJg6mUVb7RIstgEujcWWCJCnhK9jlFk3wpUDhEayArAbrXRclccRHW0pYxgXhYxrI9jp7MVxmCvU8CHRnJxeyLpviP9EbrmzSTmRMMvSo6g/Ms2Db42l1DozTd6wSFPtV0CcCMZMwQ5VDXB587NrPoTGwrg+77D4k/fZFOoF4oVOfrdRaDmGIThyRGHwEsOZPnALE0y6Tyw1lOTeuhsQdpBAhG7V89JPvOdz4/uHC1xGXkk+; 20:q9bmWRMriJH3kJF/8kp76hHni26tJMpfKqW67+nJ1HMcewIn61lmRGP60Xgm4sFDZWpduKr/BtazASJYHCzVgdSLUdLkBtCsMjiluLAdgIyi6trV6fRTiErN4U25B5TC9EAkeHdIaC3BKiLGsDPDsN8gHzjuM+tGHfWbuW11+bw= X-MS-Office365-Filtering-Correlation-Id: a714b383-4ce4-4ced-efc1-08d5b97b65d0 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2018 09:16:38.1069 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a714b383-4ce4-4ced-efc1-08d5b97b65d0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSBPR01MB2293 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.