From patchwork Wed Nov 4 23:23:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E640BC388F7 for ; Wed, 4 Nov 2020 23:26:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B36C22228 for ; Wed, 4 Nov 2020 23:26:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Bww/3yKY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732740AbgKDXZ7 (ORCPT ); Wed, 4 Nov 2020 18:25:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732730AbgKDXYC (ORCPT ); Wed, 4 Nov 2020 18:24:02 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D08DC0613CF for ; Wed, 4 Nov 2020 15:24:02 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id h64so422366ybc.1 for ; Wed, 04 Nov 2020 15:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=BhUjYszSk71wZlQtq5hRNOUlleKEQKCmateQuUAc1A0=; b=Bww/3yKY+ONgWcJ3cLoSeSWBPGJ2hOS3FdcxPbz3akcI3W+hgtgq3R4WoTmlARlZqP M5VyJmlXPSgGfPOYla6Cr/RUJZuHSF9L09ESU8I+XQA4i6jtltKJmyG4dMVDrewSrptv 76WeaxXUGcIgP8+ND2sovEN0lVt08XBee3p4OrzTZR1SCw8rQG5BOiY2hrKG0LRpmlT8 qP9m3pO8wXlMHwqmjZAhN62bCK9gb8jUT1x7Dp19hJ5/C+z5Ufi7chERIKkwy6mfEZgx QLry5+3skYHHqz3iXBKFg7dr8izgsH8XuAdEa0Soi2x7Jl6vRfd8282WGtqjKOAYIJEM FFug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BhUjYszSk71wZlQtq5hRNOUlleKEQKCmateQuUAc1A0=; b=Op4BMbI8U+8X7WoeH4O4cCnkgcvYkfDCZxUlmRuT8EcJM5eoUBm+J+oR/SXUGCYnLy Lk4oX+KriTMc10th0040Uz6zi5HQms1ozan4Govm5ixfVLq1uu6BOWRBD91gs40tzMYz 8fxdwuSnI9iutKddj+qgq01n/jZkphne7MahxCgqr/kmoTUU53MCu7pkF4nHm/tJIsCT qjuUdABXnb+Ji7wARcjW0tR8S2A7q04k8Pj2kU0dibI3rXDd4/buo9N3CGEIE73Np1mM kBYg1HU7ClL9vGHtngsjrCvnOK6pDtmTmOOVNNIrflprH1KzdvaoSAPu8BbwJ7KWfBNd Ax+A== X-Gm-Message-State: AOAM533e1QBz4iZ8bxS5h7LGa8uywwFxihmlM0bIAn77fmlm4PoNpKJ2 W358HnZ+2LwaqIU0Yq7OuE+kqbktb5JVV/8= X-Google-Smtp-Source: ABdhPJwpeEFN4gVsTaAomYr1fpuXRu2jKJlLJc0sAndfUh392UG+hSNst+uctyYjAO2rEcnP1boxrdw2x+fGHZo= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:a25:40c5:: with SMTP id n188mr274862yba.514.1604532241782; Wed, 04 Nov 2020 15:24:01 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:38 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-2-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 01/18] Revert "driver core: Avoid deferred probe due to fw_devlink_pause/resume()" From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This reverts commit 2451e746478a6a6e981cfa66b62b791ca93b90c8. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 21 --------------------- include/linux/device.h | 3 +-- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 78114ddac755..a56601e68a8c 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -51,7 +51,6 @@ static DEFINE_MUTEX(wfs_lock); static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count = 1; static unsigned int defer_fw_devlink_count; -static LIST_HEAD(deferred_fw_devlink); static DEFINE_MUTEX(defer_fw_devlink_lock); static bool fw_devlink_is_permissive(void); @@ -1472,12 +1471,6 @@ static void fw_devlink_link_device(struct device *dev) fw_ret = -EAGAIN; } else { fw_ret = -ENODEV; - /* - * defer_hook is not used to add device to deferred_sync list - * until device is bound. Since deferred fw devlink also blocks - * probing, same list hook can be used for deferred_fw_devlink. - */ - list_add_tail(&dev->links.defer_hook, &deferred_fw_devlink); } if (fw_ret == -ENODEV) @@ -1546,9 +1539,6 @@ void fw_devlink_pause(void) */ void fw_devlink_resume(void) { - struct device *dev, *tmp; - LIST_HEAD(probe_list); - mutex_lock(&defer_fw_devlink_lock); if (!defer_fw_devlink_count) { WARN(true, "Unmatched fw_devlink pause/resume!"); @@ -1560,19 +1550,8 @@ void fw_devlink_resume(void) goto out; device_link_add_missing_supplier_links(); - list_splice_tail_init(&deferred_fw_devlink, &probe_list); out: mutex_unlock(&defer_fw_devlink_lock); - - /* - * bus_probe_device() can cause new devices to get added and they'll - * try to grab defer_fw_devlink_lock. So, this needs to be done outside - * the defer_fw_devlink_lock. - */ - list_for_each_entry_safe(dev, tmp, &probe_list, links.defer_hook) { - list_del_init(&dev->links.defer_hook); - bus_probe_device(dev); - } } /* Device links support end. */ diff --git a/include/linux/device.h b/include/linux/device.h index 5ed101be7b2e..da00f8e449bb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -352,8 +352,7 @@ enum dl_dev_state { * @suppliers: List of links to supplier devices. * @consumers: List of links to consumer devices. * @needs_suppliers: Hook to global list of devices waiting for suppliers. - * @defer_hook: Hook to global list of devices that have deferred sync_state or - * deferred fw_devlink. + * @defer_hook: Hook to global list of devices that have deferred sync_state. * @need_for_probe: If needs_suppliers is on a list, this indicates if the * suppliers are needed for probe or not. * @status: Driver status information. From patchwork Wed Nov 4 23:23:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E61AAC2D0A3 for ; Wed, 4 Nov 2020 23:25:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AA4520786 for ; Wed, 4 Nov 2020 23:25:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UrcXOwPS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732869AbgKDXYP (ORCPT ); Wed, 4 Nov 2020 18:24:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732768AbgKDXYK (ORCPT ); Wed, 4 Nov 2020 18:24:10 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72E98C0613CF for ; Wed, 4 Nov 2020 15:24:10 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id d41so13729015qvc.23 for ; Wed, 04 Nov 2020 15:24:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=mDVvKrGHCP/3KBqD6Y+81Awc8s23VoJcXWEM4lmGqQk=; b=UrcXOwPS8nM7/ikskpgkXlxdwbC7fRg65vxlDw6UBrphzbOZujaNWx+XnNzrdvfUG/ /zmaPWK7O35YUG+60QYL1UALaOrJ6CfR6nAGsV2hplG8Yf26liCR0ccZzdSHdbBupXXJ rY2CqHrp20pwo/CTtzIxcuqLuKGrA14ZoXu6KCts9HWKDuYEOTfNM63I0dPMDajm9Wzp jWtQomAP9PBmL8GgNtu0xnEm8BEEHQKYoQ6NMZMN7wSfQLGLJ+qokqu6ep05laZoVOK9 pgZxS63+uVe2nNyTrMSxZTqlRYb3DosJhQyFFGylNr7KUnAU0tLAXJQV4z2s8Hl7PYzA Pi8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mDVvKrGHCP/3KBqD6Y+81Awc8s23VoJcXWEM4lmGqQk=; b=DPdPYQU6Y+C/qYZjNY6Aklv1SfRsCgjNIf/7CqGLtLUKoV6eDv37bxvMsfRVw6ZRs/ orYjlZ9uTDmVEJcVo8i3oksUA+/9Mb+lLOm3awoVqjBwQgdbkmVVhaGcZ13syjruLNHJ YKpJK/z/awEOxlEii48EKsg8SEM0tkajNhEJn9zmHImDN/6ndR+tEdlPpPh+ODa7K0b0 X/WuHuVVCX7lylYra7AD9rVxXr64Mz733XmG0ZxkO60T0WJYr0RgyZ687D0zn16179jn 1+2HepvljpnTkxKwUKtz78SQio0dxy9fo7WeSwS1TgosuyoVS3WYxTh+1wd6X6zq4mnW sqWg== X-Gm-Message-State: AOAM532stUiksuOTGx8SPBTnnay5XIBMHrVxU93sZVyX/twYZwuHMKmY n/oNhe8v4JC2S46UdABGpz2hiOrHLGMhxnQ= X-Google-Smtp-Source: ABdhPJznoHrAzCZtFLgjYhiJnzq1jZvYLPBro0eYGGwHHgz+egObOJnpHGOf9HuWhTEgl/sUfC0vy14swG3g6NM= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:ad4:4205:: with SMTP id k5mr310786qvp.10.1604532249490; Wed, 04 Nov 2020 15:24:09 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:41 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-5-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 04/18] Revert "driver core: Remove check in driver_deferred_probe_force_trigger()" From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This reverts commit fefcfc968723caf93318613a08e1f3ad07a6154f. Signed-off-by: Saravana Kannan --- drivers/base/dd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 008724f8edf1..ec67b5ffa06d 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -172,6 +172,9 @@ static void driver_deferred_probe_trigger(void) void driver_deferred_probe_force_trigger(void) { + if (!driver_deferred_probe_enable) + return; + /* * A successful probe means that all the devices in the pending list * should be triggered to be reprobed. Move all the deferred devices From patchwork Wed Nov 4 23:23:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A97C0C2D0A3 for ; Wed, 4 Nov 2020 23:25:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FC4A21734 for ; Wed, 4 Nov 2020 23:25:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OtStWDvU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732794AbgKDXYQ (ORCPT ); Wed, 4 Nov 2020 18:24:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732817AbgKDXYP (ORCPT ); Wed, 4 Nov 2020 18:24:15 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88DE4C0613D2 for ; Wed, 4 Nov 2020 15:24:15 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id w189so14486344qkd.6 for ; Wed, 04 Nov 2020 15:24:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=GBfX89ipKAdhSeKOBnmDOlEumypWnqMaH7J6rYeJ5xI=; b=OtStWDvUWMoNu1uFW93R3YUJPK4KdVXvIirI8DYQDbP1mtGw7pOxQr70pccFJI1sjW KpMBl0v04JrAPqiZ0gw8qg1aJ8V6uHQWqx8nQ9PU14zcRePMBJi/pxXFk73+WXMrui4C im5QvJFb0yOBMqPaXBpF9BBwr4fbfZh0ZBKrJfwqHEvtnoI8xPp4GvlAMGwIBxU8NwCV AZrt9Ud0caxdBy6uAsuhwVfRiGM0KDKiVOIEvEhoQQFXw8M5AdrhL3yMl7LlalVIVhc+ ozc/TIYiy9wDUKWjZQ99SfwUosjxaIt+liQq+XMXelo1UytBI+S7Gya+KRV+2klWQPmN 0rEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GBfX89ipKAdhSeKOBnmDOlEumypWnqMaH7J6rYeJ5xI=; b=RpNv0nKBXNNM/DcuSJhKsSGX6J1hh7v8bZjLLC8+W8s3z/yNHabRH6oZsZ6U2UhCMz ggc/ftpG2Ro2Y/aoPwPJFtTuQ2Z3zACqIaxaU/KtG9Q76EjQTpqq7n0pyDY9XBKMaMB8 1buHiNw+B7nIajs9wo/CplQj0hLez80gJctebLQh9OtNcW9H6UWo5XuoQVnA5oHF1V3g VzN3WghNo6D97lNN31FwPZQkeQatIaICiaqSyoj6fKP2/SY3HQUc7MfmOxXeWiMJk9ln mZxs0coLjzK4ceCroH2eu7mL5abvid59SKzQZUyKzd0Qe/56a6VyAkH2NgRfqkrTFycx WhxQ== X-Gm-Message-State: AOAM5314BnN2VLHm+wFkgiChuH9kgTLQ+GcYR2Cf8ZsXKCBTKAIKCfaj DuG0UvmpIWKc34lb/B2DyTLAld/Zj+HTjVo= X-Google-Smtp-Source: ABdhPJzpMzNB3hV/VqHLMmIuFIM8PLOEu5q57/n9A5EgKtdFkuQ/Dp5bx2fhoyEsfYeKa0SZ4GL4IQ3er3anLZc= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:ad4:4b32:: with SMTP id s18mr447192qvw.16.1604532254675; Wed, 04 Nov 2020 15:24:14 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:43 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-7-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 06/18] Revert "driver core: fw_devlink: Add support for batching fwnode parsing" From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This reverts commit 716a7a25969003d82ab738179c3f1068a120ed11. Signed-off-by: Saravana Kannan --- drivers/base/base.h | 1 - drivers/base/core.c | 116 +++-------------------------------------- drivers/base/dd.c | 8 --- include/linux/fwnode.h | 2 - 4 files changed, 7 insertions(+), 120 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index c3562adf4789..91cfb8405abd 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -156,7 +156,6 @@ extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); extern void device_block_probing(void); extern void device_unblock_probing(void); -extern void driver_deferred_probe_force_trigger(void); /* /sys/devices directory */ extern struct kset *devices_kset; diff --git a/drivers/base/core.c b/drivers/base/core.c index 6745375a8bb9..31a76159f118 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -50,9 +50,6 @@ static LIST_HEAD(wait_for_suppliers); static DEFINE_MUTEX(wfs_lock); static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count = 1; -static unsigned int defer_fw_devlink_count; -static DEFINE_MUTEX(defer_fw_devlink_lock); -static bool fw_devlink_is_permissive(void); #ifdef CONFIG_SRCU static DEFINE_MUTEX(device_links_lock); @@ -758,7 +755,7 @@ static void device_link_add_missing_supplier_links(void) int ret = fwnode_call_int_op(dev->fwnode, add_links, dev); if (!ret) list_del_init(&dev->links.needs_suppliers); - else if (ret != -ENODEV || fw_devlink_is_permissive()) + else if (ret != -ENODEV) dev->links.need_for_probe = false; } mutex_unlock(&wfs_lock); @@ -1444,116 +1441,17 @@ static void fw_devlink_link_device(struct device *dev) { int fw_ret; - if (!fw_devlink_flags) - return; - - mutex_lock(&defer_fw_devlink_lock); - if (!defer_fw_devlink_count) - device_link_add_missing_supplier_links(); - - /* - * The device's fwnode not having add_links() doesn't affect if other - * consumers can find this device as a supplier. So, this check is - * intentionally placed after device_link_add_missing_supplier_links(). - */ - if (!fwnode_has_op(dev->fwnode, add_links)) - goto out; + device_link_add_missing_supplier_links(); - /* - * If fw_devlink is being deferred, assume all devices have mandatory - * suppliers they need to link to later. Then, when the fw_devlink is - * resumed, all these devices will get a chance to try and link to any - * suppliers they have. - */ - if (!defer_fw_devlink_count) { + if (fw_devlink_flags && fwnode_has_op(dev->fwnode, add_links)) { fw_ret = fwnode_call_int_op(dev->fwnode, add_links, dev); - if (fw_ret == -ENODEV && fw_devlink_is_permissive()) - fw_ret = -EAGAIN; - } else { - fw_ret = -ENODEV; + if (fw_ret == -ENODEV && !fw_devlink_is_permissive()) + device_link_wait_for_mandatory_supplier(dev); + else if (fw_ret) + device_link_wait_for_optional_supplier(dev); } - - if (fw_ret == -ENODEV) - device_link_wait_for_mandatory_supplier(dev); - else if (fw_ret) - device_link_wait_for_optional_supplier(dev); - -out: - mutex_unlock(&defer_fw_devlink_lock); } -/** - * fw_devlink_pause - Pause parsing of fwnode to create device links - * - * Calling this function defers any fwnode parsing to create device links until - * fw_devlink_resume() is called. Both these functions are ref counted and the - * caller needs to match the calls. - * - * While fw_devlink is paused: - * - Any device that is added won't have its fwnode parsed to create device - * links. - * - The probe of the device will also be deferred during this period. - * - Any devices that were already added, but waiting for suppliers won't be - * able to link to newly added devices. - * - * Once fw_devlink_resume(): - * - All the fwnodes that was not parsed will be parsed. - * - All the devices that were deferred probing will be reattempted if they - * aren't waiting for any more suppliers. - * - * This pair of functions, is mainly meant to optimize the parsing of fwnodes - * when a lot of devices that need to link to each other are added in a short - * interval of time. For example, adding all the top level devices in a system. - * - * For example, if N devices are added and: - * - All the consumers are added before their suppliers - * - All the suppliers of the N devices are part of the N devices - * - * Then: - * - * - With the use of fw_devlink_pause() and fw_devlink_resume(), each device - * will only need one parsing of its fwnode because it is guaranteed to find - * all the supplier devices already registered and ready to link to. It won't - * have to do another pass later to find one or more suppliers it couldn't - * find in the first parse of the fwnode. So, we'll only need O(N) fwnode - * parses. - * - * - Without the use of fw_devlink_pause() and fw_devlink_resume(), we would - * end up doing O(N^2) parses of fwnodes because every device that's added is - * guaranteed to trigger a parse of the fwnode of every device added before - * it. This O(N^2) parse is made worse by the fact that when a fwnode of a - * device is parsed, all it descendant devices might need to have their - * fwnodes parsed too (even if the devices themselves aren't added). - */ -void fw_devlink_pause(void) -{ - mutex_lock(&defer_fw_devlink_lock); - defer_fw_devlink_count++; - mutex_unlock(&defer_fw_devlink_lock); -} - -/** fw_devlink_resume - Resume parsing of fwnode to create device links - * - * This function is used in conjunction with fw_devlink_pause() and is ref - * counted. See documentation for fw_devlink_pause() for more details. - */ -void fw_devlink_resume(void) -{ - mutex_lock(&defer_fw_devlink_lock); - if (!defer_fw_devlink_count) { - WARN(true, "Unmatched fw_devlink pause/resume!"); - goto out; - } - - defer_fw_devlink_count--; - if (defer_fw_devlink_count) - goto out; - - device_link_add_missing_supplier_links(); - driver_deferred_probe_force_trigger(); -out: - mutex_unlock(&defer_fw_devlink_lock); -} /* Device links support end. */ int (*platform_notify)(struct device *dev) = NULL; diff --git a/drivers/base/dd.c b/drivers/base/dd.c index ec67b5ffa06d..b42229b74fd6 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -163,14 +163,6 @@ static bool driver_deferred_probe_enable = false; * again. */ static void driver_deferred_probe_trigger(void) -{ - if (!driver_deferred_probe_enable) - return; - - driver_deferred_probe_force_trigger(); -} - -void driver_deferred_probe_force_trigger(void) { if (!driver_deferred_probe_enable) return; diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 9506f8ec0974..e0abafbb17f8 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -171,7 +171,5 @@ struct fwnode_operations { #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) extern u32 fw_devlink_get_flags(void); -void fw_devlink_pause(void); -void fw_devlink_resume(void); #endif From patchwork Wed Nov 4 23:23:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317892 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ADABC2D0A3 for ; Wed, 4 Nov 2020 23:25:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F296F20786 for ; Wed, 4 Nov 2020 23:25:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FQOg8vXe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733031AbgKDXYY (ORCPT ); Wed, 4 Nov 2020 18:24:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733027AbgKDXYW (ORCPT ); Wed, 4 Nov 2020 18:24:22 -0500 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDBAAC0613D4 for ; Wed, 4 Nov 2020 15:24:20 -0800 (PST) Received: by mail-qv1-xf4a.google.com with SMTP id dd7so7566qvb.6 for ; Wed, 04 Nov 2020 15:24:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=+Pnss2jZrmflP1wbnV6Je3ogMQfHXywiMZfR1W5P9qc=; b=FQOg8vXeOgd9z8U6hdMl0s35oKDTY2o/ycG2xGfWs76vwOr0bSbCe1uWfyGtLi8FY1 7fp8RK8A1Gt2+rZJy+F00fB7dR6NsCuPUekPmHQwz6oRXbnAJo+2PnoiRC+50ViETk1a nuIVEqhY9aWLoLDh5wUpt9Lgip56yhabhc2kFoxb4bW2At5fc8tN7uL05b/ziUWUqB9d Cv9N7La+66OgQ2Jc46NSc2rER/4Ss8uopOVJdI+aAwvripdE4aHzS6TJGAbOO61YTwsA ZafNxqqdKNo/VXLAXgumWAkM8SKhmDufAbXpP2Z1iAsdoldKQv3kEFRV55Fj+Jz1bh7k ulPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+Pnss2jZrmflP1wbnV6Je3ogMQfHXywiMZfR1W5P9qc=; b=BXujyUL8IOuZcfDC5d+DLvKUAW20qwrHYk/GZErT88c9JsmZ3BCKwY3YjWBwWB+pqo 23+iRcQ01JMbDxXTKzD+wXnvDv6SZmrNPKBgEVGM6dBmdG9l8OXZyoi+HfiY0Dd8ox/6 3G1fYHKfjLWfKB9vul5WFuMM0X48XI5BeP2/b/gSnQYyzoi6CMTpxeMD0n7rMzpe+gDY L0qu4srary8BcsFkAmZG+RP7t8V+LiMvwlGc1PhBreeOKORQu9Xz12UATdPSgO8QWAT3 cHInQ/jNo7WkczguF8z2quur8xr3VtuI4ph6vpz8nXbgssN9inePblzDSJEy4XeMRmIi +taA== X-Gm-Message-State: AOAM531tOEFfs8FNgTm3v5wT3N9hDxjtcgIHAyGkvBRo1DLKtukAT4uz MJbwyDDhhawg25wHPQwWJpN7hqgWzG7Fphc= X-Google-Smtp-Source: ABdhPJwjwtYvM7Ivv/FR7C/GC1NY2CdbIozJW3wSd7EecAEAgIod7zxLX2aUIUJyv0xOb6b1ZAh3UM7kBIOqzf0= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:ad4:59cf:: with SMTP id el15mr268323qvb.17.1604532260064; Wed, 04 Nov 2020 15:24:20 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:45 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-9-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 08/18] driver core: Add fwnode link support From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This patch adds support for creating supplier-consumer links between fwnode. It is intentionally kept simple and with limited APIs as it is meant to be used only by driver core and firmware code (Eg: device tree, ACPI, etc). We can expand the APIs later if there is ever a need for drivers/frameworks to start using them. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 95 ++++++++++++++++++++++++++++++++++++++++++ drivers/of/dynamic.c | 1 + include/linux/fwnode.h | 14 +++++++ 3 files changed, 110 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 31a76159f118..1a1d9a55645c 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -50,6 +50,101 @@ static LIST_HEAD(wait_for_suppliers); static DEFINE_MUTEX(wfs_lock); static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count = 1; +static DEFINE_MUTEX(fwnode_link_lock); + +/** + * fwnode_link_add - Create a link between two fwnode_handles. + * @con: Consumer end of the link. + * @sup: Supplier end of the link. + * + * Creates a fwnode link between two fwnode_handles. These fwnode links are + * used by the driver core to automatically generate device links. Attempts to + * create duplicate links are simply ignored and there is no refcounting. + * + * These links are automatically deleted once they are converted to device + * links or when the fwnode_handles (or their corresponding devices) are + * deleted. + */ +int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup) +{ + struct fwnode_link *link; + int ret = 0; + + mutex_lock(&fwnode_link_lock); + + /* Duplicate requests are intentionally not refcounted. */ + list_for_each_entry(link, &sup->consumers, s_hook) + if (link->consumer == con) + goto out; + + link = kzalloc(sizeof(*link), GFP_KERNEL); + if (!link) { + ret = -ENOMEM; + goto out; + } + + link->supplier = sup; + INIT_LIST_HEAD(&link->s_hook); + link->consumer = con; + INIT_LIST_HEAD(&link->c_hook); + + list_add(&link->s_hook, &sup->consumers); + list_add(&link->c_hook, &con->suppliers); +out: + mutex_unlock(&fwnode_link_lock); + + return ret; +} + +/** + * fwnode_links_purge_suppliers - Delete all supplier links of fwnode_handle. + * @fwnode: fwnode whose supplier links needs to be deleted + * + * Deletes all supplier links connecting directly to a fwnode. + */ +static void fwnode_links_purge_suppliers(struct fwnode_handle *fwnode) +{ + struct fwnode_link *link, *tmp; + + mutex_lock(&fwnode_link_lock); + list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) { + list_del(&link->s_hook); + list_del(&link->c_hook); + kfree(link); + } + mutex_unlock(&fwnode_link_lock); +} + +/** + * fwnode_links_purge_consumers - Delete all consumer links of fwnode_handle. + * @fwnode: fwnode whose consumer links needs to be deleted + * + * Deletes all consumer links connecting directly to a fwnode. + */ +static void fwnode_links_purge_consumers(struct fwnode_handle *fwnode) +{ + struct fwnode_link *link, *tmp; + + mutex_lock(&fwnode_link_lock); + list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) { + list_del(&link->s_hook); + list_del(&link->c_hook); + kfree(link); + } + mutex_unlock(&fwnode_link_lock); +} + +/** + * fwnode_links_purge - Delete all links connected to a fwnode_handle. + * @fwnode: fwnode whose links needs to be deleted + * + * Deletes all links connecting directly to a fwnode. + */ +void fwnode_links_purge(struct fwnode_handle *fwnode) +{ + fwnode_links_purge_suppliers(fwnode); + fwnode_links_purge_consumers(fwnode); +} #ifdef CONFIG_SRCU static DEFINE_MUTEX(device_links_lock); diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index fe64430b438a..9a824decf61f 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -356,6 +356,7 @@ void of_node_release(struct kobject *kobj) property_list_free(node->properties); property_list_free(node->deadprops); + fwnode_links_purge(of_fwnode_handle(node)); kfree(node->full_name); kfree(node->data); diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 593fb8e58f21..afde643f37a2 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -10,6 +10,7 @@ #define _LINUX_FWNODE_H_ #include +#include struct fwnode_operations; struct device; @@ -18,6 +19,15 @@ struct fwnode_handle { struct fwnode_handle *secondary; const struct fwnode_operations *ops; struct device *dev; + struct list_head suppliers; + struct list_head consumers; +}; + +struct fwnode_link { + struct fwnode_handle *supplier; + struct list_head s_hook; + struct fwnode_handle *consumer; + struct list_head c_hook; }; /** @@ -173,8 +183,12 @@ static inline void fwnode_init(struct fwnode_handle *fwnode, const struct fwnode_operations *ops) { fwnode->ops = ops; + INIT_LIST_HEAD(&fwnode->consumers); + INIT_LIST_HEAD(&fwnode->suppliers); } extern u32 fw_devlink_get_flags(void); +int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup); +void fwnode_links_purge(struct fwnode_handle *fwnode); #endif From patchwork Wed Nov 4 23:23:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCD62C4741F for ; Wed, 4 Nov 2020 23:24:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91E6820825 for ; Wed, 4 Nov 2020 23:24:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Dato/sGT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733039AbgKDXYZ (ORCPT ); Wed, 4 Nov 2020 18:24:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733037AbgKDXYY (ORCPT ); Wed, 4 Nov 2020 18:24:24 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 427BFC0613CF for ; Wed, 4 Nov 2020 15:24:23 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id j5so69301qtj.11 for ; Wed, 04 Nov 2020 15:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=UieoMpj8B4G4ELM6jyQkvhU8K54bvEZUN88uvzxrq1o=; b=Dato/sGTwd0wDlhkRWIv3VuShqxnqXWdeJZugh8clsc95AYuGBQFJ4oBRWJDxuIVFN 0tOSAjhCWMQYf8C1ZF2/pxlteAnpWPjhB87e57fDlwFwDW6ui1BV/rkIPlqn4WLB5oZE A++gaXeMZQuOcaIncCYHhoifNp0QV6aRdbM8JxKhbEeUq5s+94b0oUphoOHlGc7ijU3p NRqWTb1tJVJxYtHpHoFBRKZrLS/x65HlXsJkbV4cc7ZondhrKpL7dDQMTdMavPSlW6gn Qv+/3R2xqg4htPHMffx3SHvFbMSXZduSh1aEMxeSyQAKb5Nhtt3PSmyHvM3mYNJDQhU5 v9yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UieoMpj8B4G4ELM6jyQkvhU8K54bvEZUN88uvzxrq1o=; b=pgEb7MjQDBYek4pzSkDzrdVI3tAF/wrWjTdQHFR7D3TwInNlKJA6GOMwwFZbGe+tzC ln4ceW6Sxj+n1XjEn2CkHh3QwBKBKogE1S/rnTkJ6Ib7GqSEhZvhe/l+pKoehVLtD5YU L6p8jhxEr3dgza1fKz8wNAB8ihOj2t7k70+l7l9n0B2kHWZaQz4JK4dt9pEyUs2VTBlp DoniPu9vAMmXWh9LJEMSz7MXDLJk0O2IkYgVjCc5NMGKURhbmn1fb4s5yAPpPFoWYNG0 vf12CNKPIKjj2b4GiP+OufheLmgxJNYVmbIVHbuvmJJ80pHwq5aVz31+VqecoXHWhZil Kp1Q== X-Gm-Message-State: AOAM533DAyrtF2pErIxnyHhM2LLg+dS3hHkMXUdvNdJ3bHxnjoyyWVLz vZOzwRlLDbv1l+CDWsnmBs7icvQRwOUFcIY= X-Google-Smtp-Source: ABdhPJw+qdvZ55bJqASFWAsEag1odtfmLwkpRgmqmYY74br1rEUeZosUa41aLDY7Lp1MdCuP/aZglGnS4TcxzEU= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:a0c:a105:: with SMTP id d5mr249343qva.35.1604532262407; Wed, 04 Nov 2020 15:24:22 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:46 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-10-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 09/18] driver core: Allow only unprobed consumers for SYNC_STATE_ONLY device links From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org SYNC_STATE_ONLY device links only affect the behavior of sync_state() callbacks. Specifically, they prevent sync_state() only callbacks from being called on a device if one or more of its consumers haven't probed. So, creating a SYNC_STATE_ONLY device link from an already probed consumer is useless. So, don't allow creating such device links. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 1a1d9a55645c..4a0907574646 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -646,6 +646,17 @@ struct device_link *device_link_add(struct device *consumer, goto out; } + /* + * SYNC_STATE_ONLY links are useless once a consumer device has probed. + * So, only create it if the consumer hasn't probed yet. + */ + if (flags & DL_FLAG_SYNC_STATE_ONLY && + consumer->links.status != DL_DEV_NO_DRIVER && + consumer->links.status != DL_DEV_PROBING) { + link = NULL; + goto out; + } + /* * DL_FLAG_AUTOREMOVE_SUPPLIER indicates that the link will be needed * longer than for DL_FLAG_AUTOREMOVE_CONSUMER and setting them both From patchwork Wed Nov 4 23:23:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4091BC55178 for ; Wed, 4 Nov 2020 23:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF8F520825 for ; Wed, 4 Nov 2020 23:24:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I0A/S4Q3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733073AbgKDXYe (ORCPT ); Wed, 4 Nov 2020 18:24:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733062AbgKDXYc (ORCPT ); Wed, 4 Nov 2020 18:24:32 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1E31C0613D6 for ; Wed, 4 Nov 2020 15:24:30 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id l23so366006ybl.23 for ; Wed, 04 Nov 2020 15:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=HXkyO8z8X08APZbARCQP/2vgXX6ay0o50V4fzW8aU6s=; b=I0A/S4Q3YJdLVtlrppRCljyO3Nbqezxq71d58jzcyH2drf1IpsBN1WngrsFLfhJTk9 cKkqvnL+/3U4DIuWdfhDuhwsYLFWPNF78W/a6aonqyWMtVdjVAR7eB5kwpqK0KAOOL6N ZbkOjr3Nl/48a42VD9DUcuCEqznCBSw27YQ2GuEzLPSJyfF4DzgTnGjVGKpzio+WjoB4 ELOqLtaqJ/80inf1AL67t7zsC6/XrE5aL/v/W5ctpfs5PGfpoRpzSWRYGakuX3vfISnD ktU9aHTXftzitdhU+WBUAe3RXa6WeH0zPY4VncGHbbLiZmL5g+xNvv5bSAD6wYtz7yVh tnnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HXkyO8z8X08APZbARCQP/2vgXX6ay0o50V4fzW8aU6s=; b=mkT53bSQtHlCWzo6YHbdOLwQhO6chs+5fs1viCOFhACZMsF5SKkseeyvY+Imq8VzJm jB3KjmB4raH7YuHd+9xr5cpINFWc2NxJC6ald53w9gHi4c3IhYXtGxk/lkag48aVLGyk lAr97Y3f/ELzbFrz2ITU6A0VKFjw5HldsOkuuyLDN3Nu+vieR4WxRtoVriG3O/eOBIan dadCRiuUMlq4wvzlZlbja5reWg9FJROhcthEbUWbcfqncQnRNTIj2x5ayfbQk9wKbXQ0 J5aLQOOncoRDBd1PnfJVL0K9c2IgKv0PHUJ45w5N4o+JRCr+e7k6bL6jZXQqRPmp9rhX b+VA== X-Gm-Message-State: AOAM53054SNXZoXRjTsD6NzmPvw5qN0SlmLokmwZb1fUueEfaB8pCAOI F7Xst7BE+oytbg4zW442bdf1/5LgUVwBws8= X-Google-Smtp-Source: ABdhPJxd/2TF8pjIl7zpCGZmXXH1OB+9XkGkNjTUWRF8D12cDv1hHerte9U8InbxYaLdAQ3BrkNZwCbn2uTFCK8= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:a25:774f:: with SMTP id s76mr259364ybc.235.1604532269897; Wed, 04 Nov 2020 15:24:29 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:49 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-13-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 12/18] driver core: Add fw_devlink_parse_fwtree() From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This function is a wrapper around fwnode_operations.add_links(). This function parses each node in a fwnode tree and create fwnode links for each of those nodes. The information for creating the fwnode links (the supplier and consumer fwnode) is obtained by parsing the properties in each of the fwnodes. This function also ensures that no fwnode is parsed more than once by marking the fwnodes as parsed. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 19 +++++++++++++++++++ include/linux/fwnode.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 4a0907574646..ee28d8c7ee85 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1543,6 +1543,25 @@ static bool fw_devlink_is_permissive(void) return fw_devlink_flags == DL_FLAG_SYNC_STATE_ONLY; } +static void fw_devlink_parse_fwnode(struct fwnode_handle *fwnode) +{ + if (fwnode->flags & FWNODE_FLAG_LINKS_ADDED) + return; + + fwnode_call_int_op(fwnode, add_links, NULL); + fwnode->flags |= FWNODE_FLAG_LINKS_ADDED; +} + +static void fw_devlink_parse_fwtree(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *child = NULL; + + fw_devlink_parse_fwnode(fwnode); + + while ((child = fwnode_get_next_available_child_node(fwnode, child))) + fw_devlink_parse_fwtree(child); +} + static void fw_devlink_link_device(struct device *dev) { int fw_ret; diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index ec02e1e939cc..9aaf9e4f3994 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -15,12 +15,15 @@ struct fwnode_operations; struct device; +#define FWNODE_FLAG_LINKS_ADDED BIT(0) + struct fwnode_handle { struct fwnode_handle *secondary; const struct fwnode_operations *ops; struct device *dev; struct list_head suppliers; struct list_head consumers; + u32 flags; }; struct fwnode_link { From patchwork Wed Nov 4 23:23:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32B3BC388F7 for ; Wed, 4 Nov 2020 23:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD5BA20735 for ; Wed, 4 Nov 2020 23:25:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pq0CYm11" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732844AbgKDXZX (ORCPT ); Wed, 4 Nov 2020 18:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733077AbgKDXYe (ORCPT ); Wed, 4 Nov 2020 18:24:34 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12205C0613D4 for ; Wed, 4 Nov 2020 15:24:33 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id a12so375126ybc.20 for ; Wed, 04 Nov 2020 15:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=mfTizMojGYH7zl382AyPjxc3gkf67U5yOXYFJdS6QqY=; b=pq0CYm11Fj0UKb8qVcwbyM408+QTjFYePmO6qnWllEDVb7byscMhcaEBTLYr9cSO8O mqa/kKlaUfbuFzUtMT9gV+lTSCuT2f7Uok6H4EQL0PN7VzmynUXN1k7YZANVJ0i2HyF9 kYb5OL8sAtwfjE3IwxMutSrdZm8oBQTbvTNqJEGGfkxVSd3X7N2aZkPJtOt/RQ+O+fOo kTrJO3BCz7HUEVuG2X1hBn5tBY7YgQhjaNjMLH0mi0NkpVP8e9ympyUxrlulBDvWBhCK A4ylXxsx55OxKuPmRNc5sNvMqvU9SEeum7GLWTGEosf/oHKCRtHs5RN5+Oe81WXPBjut 3P/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mfTizMojGYH7zl382AyPjxc3gkf67U5yOXYFJdS6QqY=; b=pHlXsK5GFAyc5pfm2umxqdQpkqDg26eLATR8s089dhYGFs2xTtuomnBueue6YqmgLP FVwYEg2cuySps9H1Uy613b8XYgqpfxOBkp3L75NiHu1rnNhIIWEtq9CXoUKmdi5j3KaD 047lUnsdrCpACcQkgbpa+hy/eBWgwvfQT3+E247C8/LrUoMCbr/TYTbzGIfJGQd0RnVN LZipGaf73cSl88bOPWW4rS24ROZqGl28kzS1PvZKcPk2pyrfVECwSrtgOiafr7rzyJv/ 8I1PxHdbMKCYOj9JaQurQzh8r4N115JIRWMLJFig4+S01VVQ4Wf2Dq+iWuVy2dlgCCU1 9jJg== X-Gm-Message-State: AOAM5300rGOGaKsYEd8JVuR97wodqdLmwvUmpiQxBUhvdDGfl62p4sHS eRlt+byUFuZHo+0/E+a2sksS2TMCe2tBiL0= X-Google-Smtp-Source: ABdhPJwq/qmSBxreZznPwQ4n1DX1j6V4IaawuEratYZ+IGRe9YPcCLZHStla7kz1d1qZxC97x/xP/SkdJi0ocCw= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:a5b:888:: with SMTP id e8mr284703ybq.436.1604532272321; Wed, 04 Nov 2020 15:24:32 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:50 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-14-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 13/18] driver core: Add fwnode_get_next_parent_dev() helper function From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Given a fwnode, this function finds the closest ancestor fwnode that has a corresponding struct device. The function returns this struct device. This function will be used in a subsequent patch in this series. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index ee28d8c7ee85..4ae5f2885ac5 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1562,6 +1562,31 @@ static void fw_devlink_parse_fwtree(struct fwnode_handle *fwnode) fw_devlink_parse_fwtree(child); } +/** + * fwnode_get_next_parent_dev - Find device of closest ancestor fwnode + * @fwnode: firmware node + * + * Given a firmware node (@fwnode), this function finds its closest ancestor + * firmware node that has a corresponding struct device and returns that struct + * device. + * + * The caller of this function is expected to call put_device() on the returned + * device when they are done. + */ +static struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) +{ + struct device *dev = NULL; + + fwnode_handle_get(fwnode); + do { + fwnode = fwnode_get_next_parent(fwnode); + if (fwnode) + dev = get_dev_from_fwnode(fwnode); + } while (fwnode && !dev); + fwnode_handle_put(fwnode); + return dev; +} + static void fw_devlink_link_device(struct device *dev) { int fw_ret; From patchwork Wed Nov 4 23:23:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF4FDC4741F for ; Wed, 4 Nov 2020 23:25:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8811720786 for ; Wed, 4 Nov 2020 23:25:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="V8uD3HtT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732686AbgKDXZQ (ORCPT ); Wed, 4 Nov 2020 18:25:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733093AbgKDXYi (ORCPT ); Wed, 4 Nov 2020 18:24:38 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CBAC0613CF for ; Wed, 4 Nov 2020 15:24:38 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id p63so406307ybc.7 for ; Wed, 04 Nov 2020 15:24:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=PgqxUlyPagIvEZDxT3g66m4c4sZ70u9+FDBMxCsev6s=; b=V8uD3HtTn2J9X4mo0GSEjkunte9flkR1y4onoKvOje+nU9oZoLO00wuDwAoQAg9RBQ 6CaEv9ORp/gAgjGOZs+i4RtHfLIwl+s/Gt5yqp9rabmXp5AeIq7n6GdzEgxey70GOH86 LcBFPK+1llqHhXmJrVPr84tLx8nx29GJYPb35tI8qRFcyCagp4wRuARbcSY9/OxuJxYk dImR0zOUGL6+Pvuz5tqUY76xPGlpNtZeOcn7cIlO4TIq2pUis1dh8/VBIrNa6oggI3+f vUM59gbXg8Bs/Cyzg8fbcZW/J3T3iCgVvnjGpz6v96AcNublFPSR1irgh99W6EpzP2iP /gNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PgqxUlyPagIvEZDxT3g66m4c4sZ70u9+FDBMxCsev6s=; b=cK1ZM9jioxh4MhfziTapdtgAbAIQ4Ar9esgqXDEC2sJtgJCsa6pNAV0nSlDkF82pPB btpSd9BKvD6W91f3w3onPdUxEwTy4s0qLUYxNsXWoFt44AtfwUc3Iaed8UelYolOcZpr Ehi8z3M9FiZJSm7EO1Mw6LFL/FoVu3Ra5bsoz/A0pdY54XRT0SiKa4mBT+lHGW22MBfe woN4j4CPz3ZQ5gi6EeO+2E+GrjAA7cn2KgdBHn453W/wpm++Q0UyarGgDMNdWuH6q1W/ BTKWTauNL/6nfS2bqBUL3CGXsWnNQbtd+QQh6E198+7u5VD4SUdH7q1trzuz9XD3WOug zgZw== X-Gm-Message-State: AOAM530TXUt4y7UaV760+p1iM6domunVYvaW2uBImzORByLFhYlsbhHW lVjRn80YvqcN/GSEv7uHg76mDtlnDbPWN8Q= X-Google-Smtp-Source: ABdhPJw4Al74RnQAyPgArC5G5TqGiotzt3zVdJgwvW2lUqZjNt8Icke1TIAMM1tW08Zzlu6chezu+/HPpVvHFS0= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:a25:4556:: with SMTP id s83mr305182yba.478.1604532277320; Wed, 04 Nov 2020 15:24:37 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:52 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-16-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 15/18] of: property: Update implementation of add_links() to create fwnode links From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The semantics of add_links() has changed from creating device link between devices to creating fwnode links between fwnodes. So, update the implementation of add_links() to match the new semantics. Signed-off-by: Saravana Kannan --- drivers/of/property.c | 150 ++++++++++++------------------------------ 1 file changed, 41 insertions(+), 109 deletions(-) diff --git a/drivers/of/property.c b/drivers/of/property.c index 408a7b5f06a9..86303803f1b3 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1038,33 +1038,9 @@ static bool of_is_ancestor_of(struct device_node *test_ancestor, } /** - * of_get_next_parent_dev - Add device link to supplier from supplier phandle - * @np: device tree node - * - * Given a device tree node (@np), this function finds its closest ancestor - * device tree node that has a corresponding struct device. - * - * The caller of this function is expected to call put_device() on the returned - * device when they are done. - */ -static struct device *of_get_next_parent_dev(struct device_node *np) -{ - struct device *dev = NULL; - - of_node_get(np); - do { - np = of_get_next_parent(np); - if (np) - dev = get_dev_from_fwnode(&np->fwnode); - } while (np && !dev); - of_node_put(np); - return dev; -} - -/** - * of_link_to_phandle - Add device link to supplier from supplier phandle - * @dev: consumer device - * @sup_np: phandle to supplier device tree node + * of_link_to_phandle - Add fwnode link to supplier from supplier phandle + * @con_np: consumer device tree node + * @sup_np: supplier device tree node * * Given a phandle to a supplier device tree node (@sup_np), this function * finds the device that owns the supplier device tree node and creates a @@ -1074,16 +1050,14 @@ static struct device *of_get_next_parent_dev(struct device_node *np) * cases, it returns an error. * * Returns: - * - 0 if link successfully created to supplier - * - -EAGAIN if linking to the supplier should be reattempted + * - 0 if fwnode link successfully created to supplier * - -EINVAL if the supplier link is invalid and should not be created - * - -ENODEV if there is no device that corresponds to the supplier phandle + * - -ENODEV if struct device will never be create for supplier */ -static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, - u32 dl_flags) +static int of_link_to_phandle(struct device_node *con_np, + struct device_node *sup_np) { - struct device *sup_dev, *sup_par_dev; - int ret = 0; + struct device *sup_dev; struct device_node *tmp_np = sup_np; of_node_get(sup_np); @@ -1106,7 +1080,8 @@ static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, } if (!sup_np) { - dev_dbg(dev, "Not linking to %pOFP - No device\n", tmp_np); + pr_debug("Not linking %pOFP to %pOFP - No device\n", + con_np, tmp_np); return -ENODEV; } @@ -1115,53 +1090,30 @@ static int of_link_to_phandle(struct device *dev, struct device_node *sup_np, * descendant nodes. By definition, a child node can't be a functional * dependency for the parent node. */ - if (of_is_ancestor_of(dev->of_node, sup_np)) { - dev_dbg(dev, "Not linking to %pOFP - is descendant\n", sup_np); + if (of_is_ancestor_of(con_np, sup_np)) { + pr_debug("Not linking %pOFP to %pOFP - is descendant\n", + con_np, sup_np); of_node_put(sup_np); return -EINVAL; } + + /* + * Don't create links to "early devices" that won't have struct devices + * created for them. + */ sup_dev = get_dev_from_fwnode(&sup_np->fwnode); if (!sup_dev && of_node_check_flag(sup_np, OF_POPULATED)) { - /* Early device without struct device. */ - dev_dbg(dev, "Not linking to %pOFP - No struct device\n", - sup_np); + pr_debug("Not linking %pOFP to %pOFP - No struct device\n", + con_np, sup_np); of_node_put(sup_np); return -ENODEV; - } else if (!sup_dev) { - /* - * DL_FLAG_SYNC_STATE_ONLY doesn't block probing and supports - * cycles. So cycle detection isn't necessary and shouldn't be - * done. - */ - if (dl_flags & DL_FLAG_SYNC_STATE_ONLY) { - of_node_put(sup_np); - return -EAGAIN; - } - - sup_par_dev = of_get_next_parent_dev(sup_np); - - if (sup_par_dev && device_is_dependent(dev, sup_par_dev)) { - /* Cyclic dependency detected, don't try to link */ - dev_dbg(dev, "Not linking to %pOFP - cycle detected\n", - sup_np); - ret = -EINVAL; - } else { - /* - * Can't check for cycles or no cycles. So let's try - * again later. - */ - ret = -EAGAIN; - } - - of_node_put(sup_np); - put_device(sup_par_dev); - return ret; } - of_node_put(sup_np); - if (!device_link_add(dev, sup_dev, dl_flags)) - ret = -EINVAL; put_device(sup_dev); - return ret; + + fwnode_link_add(of_fwnode_handle(con_np), of_fwnode_handle(sup_np)); + of_node_put(sup_np); + + return 0; } /** @@ -1361,37 +1313,29 @@ static const struct supplier_bindings of_supplier_bindings[] = { * that list phandles to suppliers. If @prop_name isn't one, this function * doesn't do anything. * - * If @prop_name is one, this function attempts to create device links from the - * consumer device @dev to all the devices of the suppliers listed in - * @prop_name. + * If @prop_name is one, this function attempts to create fwnode links from the + * consumer device tree node @con_np to all the suppliers device tree nodes + * listed in @prop_name. * - * Any failed attempt to create a device link will NOT result in an immediate + * Any failed attempt to create a fwnode link will NOT result in an immediate * return. of_link_property() must create links to all the available supplier - * devices even when attempts to create a link to one or more suppliers fail. + * device tree nodes even when attempts to create a link to one or more + * suppliers fail. */ -static int of_link_property(struct device *dev, struct device_node *con_np, - const char *prop_name) +static int of_link_property(struct device_node *con_np, const char *prop_name) { struct device_node *phandle; const struct supplier_bindings *s = of_supplier_bindings; unsigned int i = 0; bool matched = false; int ret = 0; - u32 dl_flags; - - if (dev->of_node == con_np) - dl_flags = fw_devlink_get_flags(); - else - dl_flags = DL_FLAG_SYNC_STATE_ONLY; /* Do not stop at first failed link, link all available suppliers. */ while (!matched && s->parse_prop) { while ((phandle = s->parse_prop(con_np, prop_name, i))) { matched = true; i++; - if (of_link_to_phandle(dev, phandle, dl_flags) - == -EAGAIN) - ret = -EAGAIN; + of_link_to_phandle(con_np, phandle); of_node_put(phandle); } s++; @@ -1399,31 +1343,19 @@ static int of_link_property(struct device *dev, struct device_node *con_np, return ret; } -static int of_link_to_suppliers(struct device *dev, - struct device_node *con_np) +static int of_fwnode_add_links(struct fwnode_handle *fwnode, + struct device *dev) { - struct device_node *child; struct property *p; - int ret = 0; + struct device_node *con_np = to_of_node(fwnode); - for_each_property_of_node(con_np, p) - if (of_link_property(dev, con_np, p->name)) - ret = -ENODEV; - - for_each_available_child_of_node(con_np, child) - if (of_link_to_suppliers(dev, child) && !ret) - ret = -EAGAIN; - - return ret; -} + if (unlikely(!con_np)) + return -EINVAL; -static int of_fwnode_add_links(const struct fwnode_handle *fwnode, - struct device *dev) -{ - if (unlikely(!is_of_node(fwnode))) - return 0; + for_each_property_of_node(con_np, p) + of_link_property(con_np, p->name); - return of_link_to_suppliers(dev, to_of_node(fwnode)); + return 0; } const struct fwnode_operations of_fwnode_ops = { From patchwork Wed Nov 4 23:23:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 317895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78865C4741F for ; Wed, 4 Nov 2020 23:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 244C320786 for ; Wed, 4 Nov 2020 23:25:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DVZtwNlz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732684AbgKDXZG (ORCPT ); Wed, 4 Nov 2020 18:25:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733122AbgKDXYp (ORCPT ); Wed, 4 Nov 2020 18:24:45 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60D1DC0613CF for ; Wed, 4 Nov 2020 15:24:43 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id b25so424365ybj.2 for ; Wed, 04 Nov 2020 15:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=UFRlchaIccsk0JGD42LufUh5WHL/iRO0t5U2dOMSWQI=; b=DVZtwNlzUvhu1bT2ylduD17IaOiKiLS3Xrt/pqRBfM9JAG32+swkygL69PmMRvoWhD mj/Jpu82kklLO2wzJNnP0ZF/yF5jbqPKJkBHmeyJ74/LJDzu32tel3FiTYqhDMEt5SrI 0ubtl2yP/UPmzJtTdhZ/puSkDPJYWSZtGZ02VQobv5MVspZhus+fqBb3M0XrOe8vXB9D 90BykzQ1Y4VIrqlpT2R1/jNsyJ/fxiN4RpKrkTgO0hSeZpr1hMTlJEICVdTvq9rqJjEF aNxPctEVyYV7ognSHXbPb7puCiS4kRL9rPHzVgBbJa8t42aBS0UmoIgsQR6SU+HFLA5a j/YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UFRlchaIccsk0JGD42LufUh5WHL/iRO0t5U2dOMSWQI=; b=MnIG0AggDyD9J8ZV2EVdWPXkQ5FOUgbbxnPKfl2tQJp+dPGSlP3DnIEFEH+vb86ubo 2Kiqo9ZEekWKbrUmGf1B4whAR8u+TFFsJHCYmoPn1Y8vokwUj06343frS0kyb3YBIcGY oG/xwRwqct+ZezUol6BRKBMHQyUDQ7V2xjgbblc5gkBuuKF/1ou3FFDvhT9QKtnW6tt1 e26PtSPgx+99owSiIU4lPnUmVPYPDHOIPGa9p6x8WuvfdNCLKpzOHw0Kvvmf0880g22I 8X2dVHyEK4WPxcdNt+FNgU438x73UA8s8He1BfMpXrgWbgjywp2u9Xbuw1z3sCvKw9Er glbw== X-Gm-Message-State: AOAM5324o4+VykAjI31ViLhsufEDtOzwuL2ui5gem/l0Il96wX4hpQmE 0r+ELxStxLxhUnQAZpD1XLAWhOWqBrfbktA= X-Google-Smtp-Source: ABdhPJyFTyTz9U39nyonyGauPk616+s3tOk5O4R2ocwWkkWD1/UZ5J5Wz1mvahqfCGL8MHVgQgmjjxoLzce+IEk= Sender: "saravanak via sendgmr" X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:a25:afc1:: with SMTP id d1mr268166ybj.27.1604532282595; Wed, 04 Nov 2020 15:24:42 -0800 (PST) Date: Wed, 4 Nov 2020 15:23:54 -0800 In-Reply-To: <20201104232356.4038506-1-saravanak@google.com> Message-Id: <20201104232356.4038506-18-saravanak@google.com> Mime-Version: 1.0 References: <20201104232356.4038506-1-saravanak@google.com> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v1 17/18] driver core: Add helper functions to convert fwnode links to device links From: Saravana Kannan To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Ard Biesheuvel , Rob Herring , Frank Rowand , Marc Zyngier , Thomas Gleixner Cc: Saravana Kannan , Tomi Valkeinen , Laurent Pinchart , Grygorii Strashko , kernel-team@android.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, devicetree@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add helper functions __fw_devlink_link_to_consumers() and __fw_devlink_link_to_suppliers() that convert fwnode links to device links. __fw_devlink_link_to_consumers() is for creating: - Device links between a newly added device and all its consumer devices that have been added to driver core. - Proxy SYNC_STATE_ONLY device links between the newly added device and the parent devices of all its consumers that have not been added to driver core yet. __fw_devlink_link_to_suppliers() is for creating: - Device links between a newly added device and all its supplier devices - Proxy SYNC_STATE_ONLY device links between the newly added device and all the supplier devices of its child device nodes. Signed-off-by: Saravana Kannan --- drivers/base/core.c | 228 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index d51dd564add1..0c87ff949d81 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1585,6 +1585,234 @@ static struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) return dev; } +/** + * fw_devlink_create_devlink - Create a device link from a consumer to fwnode + * @con - Consumer device for the device link + * @sup - fwnode handle of supplier + * + * This function will try to create a device link between the consumer and the + * supplier devices. + * + * The supplier has to be provided as a fwnode because incorrect cycles in + * fwnode links can sometimes cause the supplier device to never be created. + * This function detects such cases and returns an error if a device link being + * created in invalid. + * + * Returns, + * 0 on successfully creating a device link + * -EINVAL if the device link being attempted is invalid + * -EAGAIN if the device link needs to be attempted again in the future + */ +static int fw_devlink_create_devlink(struct device *con, + struct fwnode_handle *sup, u32 flags) +{ + struct device *sup_dev, *sup_par_dev; + int ret = 0; + + sup_dev = get_dev_from_fwnode(sup); + /* + * If we can't find the supplier device from its fwnode, it might be + * due to a cyclic dependcy between fwnodes. Some of these cycles can + * be broken by applying logic. Check for these types of cycles and + * break them so that devices in the cycle probe properly. + */ + if (!sup_dev) { + /* + * DL_FLAG_SYNC_STATE_ONLY doesn't block probing and supports + * cycles. So cycle detection isn't necessary and shouldn't be + * done. + */ + if (flags & DL_FLAG_SYNC_STATE_ONLY) + return -EAGAIN; + + sup_par_dev = fwnode_get_next_parent_dev(sup); + + /* + * If the supplier's parent is dependent on the consumer, then + * the consumer-supplier dependency is a false dependency. So, + * treat it as an invalid link. + */ + if (sup_par_dev && device_is_dependent(con, sup_par_dev)) { + dev_dbg(con, "Not linking to %pfwP - False link\n", + sup); + ret = -EINVAL; + } else { + /* + * Can't check for cycles or no cycles. So let's try + * again later. + */ + ret = -EAGAIN; + } + + put_device(sup_par_dev); + return ret; + } + + /* + * If we get this far and fail, this is due to cycles in device links. + * Just give up on this link and treat it as invalid. + */ + if (!device_link_add(con, sup_dev, flags)) + ret = -EINVAL; + put_device(sup_dev); + + return ret; +} + +/** + * __fw_devlink_link_to_consumers - Create device links to consumers of a device + * @dev - Device that needs to be linked to its consumers + * + * This function looks at all the consumer fwnodes of @dev and creates device + * links between the consumer device and @dev (supplier). + * + * If the consumer device has not been added yet, then this function creates a + * SYNC_STATE_ONLY link between @dev (supplier) and the closest ancestor device + * of the consumer fwnode. This is necessary to make sure @dev doesn't get a + * sync_state() callback before the real consumer device gets to be added and + * then probed. + * + * Once device links are created from the real consumer to @dev (supplier), the + * fwnode links are deleted. + */ +static void __fw_devlink_link_to_consumers(struct device *dev) +{ + struct fwnode_handle *fwnode = dev->fwnode; + struct fwnode_link *link, *tmp; + + list_for_each_entry_safe(link, tmp, &fwnode->consumers, s_hook) { + u32 dl_flags = fw_devlink_get_flags(); + struct device *con_dev; + bool own_link = true; + int ret; + + con_dev = get_dev_from_fwnode(link->consumer); + /* + * If consumer device is not available yet, make a "proxy" + * SYNC_STATE_ONLY link from the consumer's parent device to + * the supplier device. This is necessary to make sure the + * supplier doesn't get a sync_state() callback before the real + * consumer can create a device link to the supplier. + * + * This proxy link step is needed to handle the case where the + * consumer's parent device is added before the supplier. + */ + if (!con_dev) { + con_dev = fwnode_get_next_parent_dev(link->consumer); + /* + * However, if the consumer's parent device is also the + * parent of the supplier, don't create a + * consumer-supplier link from the parent to its child + * device. Such a dependency is impossible. + */ + if (con_dev && + fwnode_is_ancestor_of(con_dev->fwnode, fwnode)) { + put_device(con_dev); + con_dev = NULL; + } else { + own_link = false; + dl_flags = DL_FLAG_SYNC_STATE_ONLY; + } + } + + if (!con_dev) + continue; + + ret = fw_devlink_create_devlink(con_dev, fwnode, dl_flags); + put_device(con_dev); + if (!own_link || ret == -EAGAIN) + continue; + + list_del(&link->s_hook); + list_del(&link->c_hook); + kfree(link); + } +} + +/** + * __fw_devlink_link_to_suppliers - Create device links to suppliers of a device + * @dev - The consumer device that needs to be linked to its suppliers + * @fwnode - Root of the fwnode tree that is used to create device links + * + * This function looks at all the supplier fwnodes of fwnode tree rooted at + * @fwnode and creates device links between @dev (consumer) and all the + * supplier devices of the entire fwnode tree at @fwnode. See + * fw_devlink_create_devlink() for more details. + * + * The function creates normal (non-SYNC_STATE_ONLY) device links between @dev + * and the real suppliers of @dev. Once these device links are created, the + * fwnode links are deleted. When such device links are successfully created, + * this function is called recursively on those supplier devices. This is + * needed to detect and break some invalid cycles in fwnode links. + * + * In addition, it also looks at all the suppliers of the entire fwnode tree + * because some of the child devices of @dev that have not been added yet + * (because @dev hasn't probed) might already have their suppliers added to + * driver core. So, this function creates SYNC_STATE_ONLY device links between + * @dev (consumer) and these suppliers to make sure they don't execute their + * sync_state() callbacks before these child devices have a chance to create + * their device links. The fwnode links that correspond to the child devices + * aren't delete because they are needed later to create the device links + * between the real consumer and supplier devices. + */ +static void __fw_devlink_link_to_suppliers(struct device *dev, + struct fwnode_handle *fwnode) +{ + bool own_link = (dev->fwnode == fwnode); + struct fwnode_link *link, *tmp; + struct fwnode_handle *child = NULL; + u32 dl_flags; + + if (own_link) + dl_flags = fw_devlink_get_flags(); + else + dl_flags = DL_FLAG_SYNC_STATE_ONLY; + + list_for_each_entry_safe(link, tmp, &fwnode->suppliers, c_hook) { + int ret; + struct device *sup_dev; + struct fwnode_handle *sup = link->supplier; + + ret = fw_devlink_create_devlink(dev, sup, dl_flags); + if (!own_link || ret == -EAGAIN) + continue; + + list_del(&link->s_hook); + list_del(&link->c_hook); + kfree(link); + + /* If no device link was created, nothing more to do. */ + if (ret) + continue; + + /* + * If a device link was successfully created to a supplier, we + * now need to try and link the supplier to all its suppliers. + * + * This is needed to detect and delete false dependencies in + * fwnode links that haven't been converted to a device link + * yet. See comments in fw_devlink_create_devlink() for more + * details on the false dependency. + * + * Without deleting these false dependencies, some devices will + * never probe because they'll keep waiting for their false + * dependency fwnode links to be converted to device links. + */ + sup_dev = get_dev_from_fwnode(sup); + __fw_devlink_link_to_suppliers(sup_dev, sup_dev->fwnode); + put_device(sup_dev); + } + + /* + * Make "proxy" SYNC_STATE_ONLY device links to represent the needs of + * all the descendants. This proxy link step is needed to handle the + * case where the supplier is added before the consumer's parent device + * (@dev). + */ + while ((child = fwnode_get_next_available_child_node(fwnode, child))) + __fw_devlink_link_to_suppliers(dev, child); +} + static void fw_devlink_link_device(struct device *dev) { int fw_ret;